首页 > 移动平台 > 详细

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

时间:2015-07-06 12:06:50      阅读:3476      评论:0      收藏:0      [点我收藏+]
<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

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

原文:http://www.cnblogs.com/zhangchenglzhao/p/4623608.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!