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