我们在mybatis判断char、varchar等字符类型的字段习惯这样判断
<if test="status != null and status != ''">
status = #{status}
</if>
CV代码一多,对于数值类型的字段这样判断,就会出现0进不了判断的现象。
这是因为 status != ''经过mybatis编译后变为:status !=0
所以0进不了判断。
解决方法
数值类型的直接!= null就够了
<if test="status != null">
status = #{status}
</if>
如果非要写 != '',可以这么写
<if test="status == 0 || status != null and status != ''">
status = #{status}
</if>