mybatis 解析Integer为0和浮点型为0.00的属性,解析成空字符串

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

type != ''不等于空应该使用在字符串类型的属性上,不是字符串的属性最好不要加这个判断。

详细分析:http://www.jianshu.com/p/91ed365c0fdd

mybaits源码分析:http://www.cnblogs.com/V1haoge/tag/MyBatis/

猜你喜欢

转载自blog.csdn.net/h363659487/article/details/80733906
今日推荐