小坑背景:今天在往mysql数据库里插入数据的时候,有个字段类型stat( tinyint(1))用来做状态判断的,本来取值是可以为0的,在mybatis中的条件里原来是这样写的:
<if test="stat != null and stat !=''"> and stat = #{stat,jdbcType=INTEGER} </if>
习惯这样写,非空非null
原因小记:mybatis源码里在判断Integer类型时候,默认把0值当做空值来处理了
解决方案:<if test="stat != null "> and stat = #{stat,jdbcType=INTEGER} </if>,在Integer类型取值允许为0值的时候不要加 != ‘’的判断。
记录下来,防止再次踩坑。。。。。。