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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM