mybatis foreach 遍历list中的坑
将jdbc改写为mybatis时,传入的条件为list使用到的标签是<where> 、<choose>、<when>、<if>、<foreach>因为判断list集合时判断条件不全,导致sql执行错误,下面是正确的判断条件
<where>
<choose>
<when test="unitList != null and ! unitList.isEmpty() and unitList.size() > 0">
(tab2.id IN
<foreach collection="unitList" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND tab1.`status` = #{deviceStatus})
<if test="zoonList != null and ! zoonList.isEmpty() and zoonList.size() > 0">
OR (tab2.leaderId IN
<foreach collection="zoonList" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND tab1.`status` = #{deviceStatus})
</if>
</when>
<when test="zoonList != null and ! zoonList.isEmpty() and zoonList.size() > 0">
tab2.leaderId IN
<foreach collection="zoonList" item="item" index="index"
open="(" separator="," close=")">
#{item}
</foreach>
AND tab1.`status` = #{deviceStatus}
</when>
</choose>
</where>
最新文章
- HTML 事件(四) 模拟事件操作
- ASP.NET MVC之路由特性以及母版页呈现方式(十二)
- 转!java基础笔记
- [译]在Mac上运行ASP.NET 5
- VC++ 限制窗口的大小范围的方法
- JSP JSTL EL
- tomcat下jndi配置
- 创建xml时,设置xml编码问题
- Activti跳过中间节点的helloworld实例程序
- 使用sui实现的选择控件【性别、日期、省市级联】
- WPF学习之路初识
- 提交App到Apple Store(Xcode4)
- UML之轻松入门(2)-掌握Junit,让我们的开发更高效
- Css实现一个简单的幻灯片效果页面
- IntelliJ idea学习资源
- ajax跨域例子
- python入门-基础语法
- 1.5、CDH 搭建Hadoop在安装之前(定制安装解决方案)
- 日志审计系统、事件日志审计、syslog审计
- sublime text3 -- JavaScript Completions
热门文章
- jenkins git can&#39;t work ERROR: Timeout after 10 minutes ERROR: Error fetching remote repo &#39;origin&#39;
- element table 二次封装 父子组件传值 组件通信
- 51Nod 算法马拉松12 移数博弈
- double保留两位小数
- 文件上传中UUID的解读
- 2、Kafka架构
- 类自动调用to.string方法
- 力扣(LeetCode)605. 种花问题
- 版本控制 version control
- yum命令报错 yum update File ";/usr/bin/yum";, line 30 except KeyboardInterrupt, e: --CentOS7.5