mybatis 的xml,Integer类型参数bug问题
当有Integer数据类型的参数值为0时,如pid=0,xml中pid==“” 判断为ture,即不走条件语句
<if test="pid != null and pid != '' ">
AND a.pid = #{pid}
</if>
正确写法一:还要加上一句 or pid==0
<if test="pid != null and pid != '' or pid ==0">
AND a.pid = #{pid}
</if>
正确方法二:去掉and pid != ''的条件
<if test="pid != null ">
AND a.pid = #{pid}
</if>
原因分析
本文转载:链接: link