mybatis 传参为 Integer 时 ,Mapper 文件 中判断 条件 问题。

<if test="valiStatus==null || valiStatus=='' || valiStatus==4 ">
                b.work_permit_card_cert is not null and b.work_permit_card_cert!=1 and b.delete_flag =0
            </if>
            <if test="valiStatus==0">
                u.user_type = 0 and b.work_permit_card_cert = 0 and b.delete_flag =0 
            </if>
            <if test="valiStatus==2">
                u.user_type=1 and b.work_permit_card_cert=2 and b.delete_flag =0 
            </if>

其中viliStauts 是一个 Integer 型的参数 , 如果 传入 4 和2  是可以正确的执行 if 条件的 。。

但是如果传入0 的话 , 就会出现 前两个 if 条件都判断正确的情况,导致sql 错误。

解决办法是不要写valiStatus=='' 的判断,(以后要注意类型问题,Integer 就不要判断 ==''了)

其他知识点:  like concat('%'+#{a} + '%');

      并且 : 使用 and

原文地址:https://www.cnblogs.com/zhangchenglzhao/p/4623608.html