根据状态查询是,由于status是Integer类型,所以当前状态为0时,变成了查询了所有的状态信息。
<if test="requestParam.status != null and requestParam.status != ''">and s.status = #{requestParam.status}
</if>
原因:
MyBatis因自身原因默认了 Integer类型数据值等于0时 为 ""(空字符串)
解决办法:
1. 某些情况下,可以在Controller处就拦截,并向前台提示,比如:“必须输入有效数字”,不让他再往后传。
2. 将判断条件version != ''删去,不让它判断。
如:
<if test="requestParam.status != null">and s.status = #{requestParam.status}
</if>
3. 单独加上当status为0的特殊情况弊端:就是当有哪位仁兄真的用这个方法传了个空字符串,就无法判断。
如:
<if test="requestParam.status != null and requestParam.status != '' or requestParam.status == 0 ">and s.status = #{requestParam.status}
</if>
当然,如果想默认输入为0时查询所有(类似于上述问题示例)或者是后面想转为空字符串,
可以不用改,也算是巧用"bug"。
4.最后就是可以将Integer类型转成字符串,也是ok的。