在使用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的数据失败
本文探讨了在使用MyBatis进行多条件过滤查询时遇到的问题,特别是针对整数类型的字段,如Integer,在使用非空判断时可能出现的误解及解决方法。
1684

被折叠的 条评论
为什么被折叠?



