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>
但是我觉得上面没有任何问题。