0
点赞
收藏
分享

微信扫一扫

mybatis避坑,多条件查询时整数类型过滤条件的坑

E_topia 2022-03-25 阅读 20

在使用mybatis多条件过滤查询时,一般会这么写:

select id,name,status
from stu
where id > 10
<if test="name != null and name != ''">
    AND name = like concat('%',#{userName},'%')
</if>
<if test="status!= null and status != ''">
    AND status = #{status}
</if>

一般情况下是没有问题的,但如果当status为整数类型,如Integer,此时mybatis会把“status != ’ ’ ”识别为“status != 0 ”,导致想查询状态值为0的数据失败

举报

相关推荐

0 条评论