for each
2015-10-28 00:00
134 查看
SELECT * FROM USER WHERE id=1 OR id=10 OR id=16
SELECT * FROM USER WHERE id IN(1,10,27)
SELECT * FROM USER WHERE id IN(1,10,27)
<!-- 定义sql片段 查询条件 --> <sql id="user_query_where"> <if test="userCustom!=null"> <if test="userCustom.sex!=null and userCustom.sex!=''"> user.sex=#{userCustom.sex} </if> <if test="userCustom.username!=null and userCustom.username!=''"> user.username LIKE '%${userCustom.username}%' </if> <if test="ids!=null"> <!-- 使用foreach遍历传入的ids --> <!--collection 指定输入对象的集合属性 item 每个遍历生成的对象 open 开始遍历时拼接的串 close 结束遍历时拼接的串 separator 遍历时两个对象需要拼接的串 --> <foreach collection="ids" item="id" open=" and (" close=")" separator="or"> id=#{id} </foreach> </if> </if> </sql> 另外一种方法 <select id="selectUserByList" parameterType="java.util.List" resultType="user"> select * from user <where> <!-- 传递List,List中是pojo --> <if test="list!=null"> <foreach collection="list" item="item" open="and id in("separator=","close=")"> #{item.id} </foreach> </if> </where> </select>
相关文章推荐
- javascript图片轮播之gallery.js
- 对于使用了SSH造成的中文乱码问题,4大解决方法
- 黑马程序员****OC语言基础****MRC的理解
- 近视的原因
- linux文件以及目录管理
- Linux 文件查阅
- SHA-1证书隐患多 升级SHA-2才安全
- 自动生成新的表单元素
- SpringMVC
- Spring源码解析
- HTML文档DOCTYPE声明
- html head 头部中的元素内容
- HTML标签类型及写法
- git学习
- 怎样用MindMapper中的色彩来装饰主题背景
- 中文短信编码(一)
- 中文短信编码(一)
- 承接游戏UI美术外包【厦门巨游网络科技有限公司】
- 教你Zbrush怎样使用3D Layers
- 在蜂窝教育努力学习的日子