mybatis 解析Integer为0的属性,解析成空字符串

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

相关文章
相关标签/搜索