问题
mybatis 传入Integer对象 时,if 无法通过以下方式判断数字 0
<if test="lastHandleCode != null and lastHandleCode!=''">
AND t.last_handle_code = #{lastHandleCode}
</if>
mybatis的 if 将 0 认为是 ’ ’ ,所以这样判断是无法进入条件的,但是将数字换为非 0 就可以了;
解决方法
<if test= "lastHandleCode != null and lastHandleCode !='' or lastHandleCode == 0">
AND t.last_handle_code = #{lastHandleCode}
</if>
原因
对于Integer类型属性,在判断不等于’‘时,例如age != ‘’,OGNL会返回’'的长度,源码:(s.length() == 0) 0.0 : Double.parseDouble( s ),因此表达式age != ''被当做age != 0来判断,所以当age为0时,if条件判断不通过。
详细解析
https://cloud.tencent.com/developer/article/1543633
https://blog.csdn.net/qq_30038111/article/details/82665763