Mybatis把0识别为null

来源:互联网 发布:淘宝标题营销词 编辑:程序博客网 时间:2024/04/28 12:59

今天项目中定义了Integer type,对其赋值0传到mybatis。查询type=0的数据,但是条件并没有生效。条件如下:

<where>  
    <if test="type != null and type !=' ' "> type=#{type}  
    </if>  
</where>  

如果不是null并且不是空字符串才去修改这个值,但这样写只能针对字符串(String)类型,如果是Integer类型的话就会有问题了。mybatis会把0识别为空字符串,所以想避免这个问题,条件写成:

<where>  
    <if test="type != null"> type=#{type}  
    </if>  
</where>