使用 , 拼接

查询条件dto

public class queryCondition
{
 private String[] stuIds;
 private String name;
}

查询sqlMap

<select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
 select id,name from student
 <dynamic prepend="where">
  <isNotNull property="stuIds" prepend="and">
   <iterate property="stuIds" open="id in (" close=")" conjunction=",">
    #stuIds[]#
   </iterate>
  </isNotNull>
  <isNotNull property="name" prepend="and">
   name like '%$name$%'
  </isNotNull>
 </dynamic>
</select>

在查询条件中有一个数组stuIds,在动态标签中进行遍历,看每一个student的id是否在该数组中。

发出的语句 select id,name from student where  id in ( ? , ?) ...

使用 or 拼接

查询条件dto

public class queryCondition
{
 private List<Student> lst;
 private String name;
}

查询sqlMap

<select id="selectStu" parameterClass="cn.xy.queryCondition" resultClass="cn.xy.Student">
 select id,name from student
 <dynamic prepend="where">
  <isNotNull property="lst" prepend="and">
   <iterate property="lst" open=" (" close=")" conjunction="or">
    id = #lst[].id#
   </iterate>
  </isNotNull>
  <isNotNull property="name" prepend="and">
   name like '%$name$%'
  </isNotNull>
 </dynamic>
</select>

发出的语句 select id,name from student where  (id = ?   or   id = ?)...

引用自:http://www.cnblogs.com/Struts-pring/p/5127510.html

ibatis (mybatis) for循环拼接语句【转】的更多相关文章

  1. ibatis Dynamic总结(ibatis使用安全的拼接语句,动态查询)

    ibatis中使用安全的拼接语句,动态查询,ibatis比JDBC的优势之一,安全高效 说明文字在注释中 一.引入 一个小例子  <select id="selectAllProduc ...

  2. ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]>

    ibatis mybatis sql语句配置 符号不兼容 大于号 小于号<!CDATA[ ]> 因为这个是xml格式的,所以不允许出现类似">"这样的字符,但是都 ...

  3. ibatis/mybatis显示sql语句 log4j.properties配置文件

    将ibatis/mybatis log4j运行级别调到DEBUG可以在控制台打印出ibatis运行的sql语句,方便调试: ### 设置Logger输出级别和输出目的地 ### log4j.rootL ...

  4. iBatis --> MyBatis

    从 Clinton Begin 到 Google(从 iBatis 到 MyBatis,从 Apache Software Foundation 到 Google Code),Apache 开源代码项 ...

  5. 详解Java的MyBatis框架中SQL语句映射部分的编写

    这篇文章主要介绍了Java的MyBatis框架中SQL语句映射部分的编写,文中分为resultMap和增删查改实现两个部分来讲解,需要的朋友可以参考下 1.resultMap SQL 映射XML 文件 ...

  6. iBatis & myBatis & Hibernate 要点记录

    iBatis & myBatis & Hibernate 要点记录 这三个是当前常用三大持久层框架,对其各自要点简要记录,并对其异同点进行简单比较. 1. iBatis iBatis主 ...

  7. JDBC、ibatis(mybatis)、Hibernate有什么不同?

    ①JDBC编程流程固定,同时将sql语句和java代码混在了一起,经常需要拼凑sql语句,细节很繁琐: ②ibatis(mybatis)它不完全是一个ORM框架,因为MyBatis需要程序员自己编写S ...

  8. 关于SSM中mybatis向oracle添加语句采用序列自增的问题

    在SSM向oracle数据库中插入语句时,报错如下: ### Error updating database.  Cause: java.sql.SQLException: 不支持的特性 ### SQ ...

  9. paip.环境配置整合 ibatis mybatis proxool

    paip.环境配置整合 ibatis mybatis proxool  索引: ///////////1.调用 ///////////////2. ibatis 主设置文件  com/mijie/ho ...

随机推荐

  1. PHP使用Redis实现消息队列

    消息队列可以使用MySQL来实现,可以参考博客PHP使用MySQL实现消息队列,虽然用MySQL可以实现,但是一般不这么用,因为MySQL的数据都存在硬盘中,而从硬盘中对MySQL的操作,I/O花费的 ...

  2. PAT 1009 说反话

    https://pintia.cn/problem-sets/994805260223102976/problems/994805314941992960 给定一句英语,要求你编写程序,将句中所有单词 ...

  3. multer处理post请求的代码演示

    let express = require('express'); let multer = require('multer'); let mObj = multer({dest:__dirname+ ...

  4. Kali2.0的简单使用--开启root用户登录

    1. 安装完kali之后 2. 修改/etc/ssh/sshd_conf的文件 将: #PasswordAuthentication no 修改为: PasswordAuthentication ye ...

  5. c#通过反射移除所有事件

    移除全部事件委托 C# code   ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 3 ...

  6. C/S架构引用Lodop 如何在C#调用web打印控件Lodop

    lodop是web打印控件,引用安装目录下的ocx文件,可以在c/s架构中使用. 该文件所在路径:C:\Program Files (x86)\MountTaiSoftware\Lodop 有32位和 ...

  7. codeforces548B

    Mike and Fun CodeForces - 548B Mike and some bears are playing a game just for fun. Mike is the judg ...

  8. BZOJ1018[SHOI2008]堵塞的交通——线段树

    题目描述 有一天,由于某种穿越现象作用,你来到了传说中的小人国.小人国的布局非常奇特,整个国家的交通系统可以被看成是一个2行C列的矩形网格,网格上的每个点代表一个城市,相邻的城市之间有一条道路,所以总 ...

  9. BZOJ5338 [TJOI2018] Xor 【可持久化Trie树】【dfs序】

    题目分析: 很无聊的一道题目.首先区间内单点对应异或值的询问容易想到trie树.由于题目在树上进行,case1将路径分成两段,然后dfs的时候顺便可持久化trie树做询问.case2维护dfs序,对d ...

  10. jupyter快捷键

    jupyter快捷键(jupyter有两个模式,命令模式和编辑模式) 当前cell侧边为蓝色时,表示此时为命令模式,按Enter切换为编辑模式 当前cell侧边为绿色时,表示此时为编辑模式,按Esc切 ...