使用Mybatis時,經常會判斷屬性是否爲空源碼分析
1 <if test="type != null and type != ''"> 2 and type = #{type} 3 </if>
當type爲Integer類型,而且type值爲0時,該if判斷卻爲false。spa
當type爲0時,Mybatis會解析成'' 空字符串。code
爲了不這個問題,改爲下面這樣寫,去掉對空字符的判斷,就解決了該問題blog
<if test="type != null"> and type = #{type} </if>
詳細分析:http://www.jianshu.com/p/91ed365c0fdd字符串
mybaits源碼分析:http://www.cnblogs.com/V1haoge/tag/MyBatis/源碼