在使用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的数据失败