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/

  

posted @ 2017-07-19 16:30  chen-hao  阅读(5216)  评论(0编辑  收藏  举报