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