码迷,mamicode.com
首页 > 数据库 > 详细

mybatis sql语句中 like in() 长度为0或null的情况

时间:2019-09-18 10:33:37      阅读:281      评论:0      收藏:0      [点我收藏+]

标签:test   index   rom   name   标签   size   for   sql语句   null   

mybatis sql语句中 like in() 长度为0或null的情况

比如:

select * from A 
where colName LIKE IN
<foreach collection="moCodeList" item="item" index="index" open="(" close=")" separator=",">
#{item}
</foreach>

想要查询 colName LIKE IN ( 列表) 条件下的数据,如果列表 为null 或者长度为0
语句就变成了 colName LIKE IN () 这样的语法是不对的

改进

select * from A 
where colName LIKE IN
<if test="moCodeList != null and moCodeList.size>0">
   <foreach collection="moCodeList" item="item" index="index" open="(" close=")" separator=",">
     #{item}
   </foreach>
</if>
<if test="moCodeList==null or moCodeList.size==0">
    and 1=0
</if>

用if 标签 来区分,如果LIKE IN 条件里的列表为0 那么,走条件 1=0

mybatis sql语句中 like in() 长度为0或null的情况

标签:test   index   rom   name   标签   size   for   sql语句   null   

原文地址:https://www.cnblogs.com/magicya/p/11540013.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!