今日开发所遇到的问题

1.静态资源放行

注意当在web.xml中

   <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

/:拦截所有的请求(jsp除外),所以请求静态资源就必须要设置静态资源放行

    <!-- 静态资源放行 -->
    <mvc:resources location="/WEB-INF/js/" mapping="/js/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/css/" mapping="/css/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/fonts/" mapping="/fonts/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/images/" mapping="/images/**"></mvc:resources>
    <mvc:resources location="/WEB-INF/js-l/" mapping="/js-l/**"></mvc:resources>

注意:location 后的 js ,css,images的 / 斜杠一定要写。

但是当

   <servlet-mapping>
    <servlet-name>ego-portal</servlet-name>
    <url-pattern>*.html</url-pattern>
  </servlet-mapping>
的时候,静态资源不会被拦截,所以并不用设置放行,但是如果静态资源放在WEB-INF的时候,是访问不到的。

2.@RequestPara( )的使用

@RequestParam(defaultValue="1") default:默认值,当前端没有传递值时候会用到
@RequestParam(value="name1")   当前端传递过来的属性名称和接受的属性名称不一样的时候

3.mybatis中参数的问题

出现问题的代码

List<Comment_1> selAllComment_1ByArticle_id(int article_id);
	<select id="selAllComment_1ByArticle_id" resultMap="myMap">
		select * from comment_1
		<where>
			<if test="#{0} !=null and #{0}  !=''">
				and article_id = #{0}
			</if>
		</where>
	</select>

解决方式:

List<Comment_1> selAllComment_1ByArticle_id(@Param("article_id")int article_id);
	<select id="selAllComment_1ByArticle_id" resultMap="myMap">
		select * from comment_1
		<where>
			<if test="article_id  !=null and article_id  !=''">
				and article_id = #{article_id}
			</if>
		</where>
	</select>

然后 又出现问题:

<collection property="list_comment_2" ofType="comment_2" select="com.ai.mapper.Comment_2Mapper.selComment_2ByComment_1_id" column="comment_1_id">
</collection>
Comment_2 selComment_2ByComment_1_id(@Param("comment_1_id")int comment_1_id);
<select id="selComment_2ByComment_1_id" resultType="comment_2">
	select * from comment_2
	<where>
		<if test="comment_1_id !=null and comment_1_id !=''">
			and comment_1_id = #{comment_1_id}
		</if>
	</where>
</select>

按理说应该是没问题的吧,但是结果是不行的。

There is no getter for property named 'xxxx' in 'class xxxx

检查了很久,还是不行

使用了这汇总方式解决:_parameter来解决

	<select id="selComment_2ByComment_1_id" resultType="comment_2">
		select * from comment_2
		<where>
			<if test="_parameter !=null and _parameter !=''">
				and comment_1_id = #{_parameter}
			</if>
		</where>
	</select>
但是我觉得上面没有任何问题。



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值