问题描述
在进行搜索测试时,当参数为 0 mybatis不识别
在mybatis中,参数类型为INTEGER时传入参数为0 mybatis处理时默认为false(为空:例 status=’’),不生效。
<if test="status != ''">
and orders.status = #{status,jdbcType=INTEGER}
</if>
在数据库中测试是生效的
解决方案
1.添加一个为0判断or status == 0
<if test="status != '' and status != null or status == 0">
and orders.status = #{status,jdbcType=INTEGER}
</if>
2.去除为空字符判断
<if test="status != null">
and orders.status = #{status,jdbcType=INTEGER}
</if>
以上解决方式的意思是一致:将有为空的可能去掉。
参考文章
https://blog.csdn.net/weixin_33690367/article/details/93810005
https://blog.csdn.net/qq_38387867/article/details/81189648