Mybatis中Integer类型的判断<if test=“status!= null and status!= ‘‘“>问题
Mybatis在进行<if test="
status!= null and
status!= ''">
判空操作时,如果status为0的时候,该判断条件的值为false,也就是说Mybatis此时把0作为null来进行判断的
此时就会出现问题,在查询状态是0的数据时,查询的是全部数据
解决办法:
将判断条件修改为:<if test="
status!= null
">
结论:
<if test="status != null">
中status为integer类型的,status=0的判断结果为true。<if test="status != null and status != ''">
中status为integer类型的,status=0的判断结果为false,mybatis把status看作string来进行判断。