mybatis 解析Integer為0的屬性,解析成空字符串


使用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/

  


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM