mybatis 传入Integer类型的参数,当值为0时,查询的结果有误。

<if test=" isDelete != null and isDelete != '' ">
     and is_delete=#{isDelete}
</if>

通过将sql打印出来,发现这个条件没有生效。

总结:mybatis 传入Integer类型的参数,当参数值为0时,会被看做为空字符串,所以空值判断不能用!=''

这样Integer类型的参数空值判断,只需要判断是否为null。

<if test=" isDelete != null ">
     and is_delete=#{isDelete}
</if>

 

 posted on 2021-10-14 14:32  会飞的金鱼  阅读(262)  评论(0)    收藏  举报