Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。 
Iterate 的属性: 
      prepend  - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选) 
      property  - 类型为 java.util.List 的用于遍历的元素(必选) 
      open  -  整个遍历内容体开始的字符串,用于定义括号(可选) 
      close  -整个遍历内容体结束的字符串,用于定义括号(可选) 
      conjunction -  每次遍历内容之间的字符串,用于定义 AND 或 OR(可选) 
      遍历类型为 java.util.List的元素。

例子: 
<iterate prepend=”AND” property=”userNameList” 
open=”(” close=”)” conjunction=”OR”> 
username=#userNameList[]# 
</iterate>

ibatis中如何配置in语句,需要迭代,不能直接用string的写法
<select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
select *from tablewhere name in 
<iterate property="ids" conjunction="," close=")" open="(" /> 
#value[]# 
</iterate>
and code=#code#
</select>
myPramBean
{
private String code;
private List ids;
...
}

eg:
<delete id="member.batchDelete" parameterClass="java.util.List">
      DELETE FROM member where id IN
      <iterate conjunction="," open="(" close=")" >
          #value[]# 
      </iterate>
</delete>

注意:使用<iterate>时,在List元素名后面包括方括号[]非常重要,方括号[]将
对象标记为List,以防解析器简单地将List输出成String。

posted on 2010-02-02 15:49 飞熊 阅读(20034) 评论(3)  编辑  收藏 所属分类: Ibatis

评论

# re: ibatis的iterate使用 2011-10-06 01:10 wiky

ibatis中如何配置in语句,需要迭代,不能直接用string的写法
<select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
select *from tablewhere name in 
<iterate property="ids" conjunction="," close=")" open="(" /> 
#value[]# 
</iterate>
and code=#code#
</select>

#value[]# 要改成#ids[]# 才行  回复  更多评论

# re: ibatis的iterate使用[未登录] 2013-08-22 13:36 呵呵

第三种:in后面的数据确定,使用string传入 
<select id="GetEmailList_Test2" parameterClass="TestIn" resultClass="EmailInfo_"> 
select * 
from MailInfo with (nolock) 
where ID in 
($StrValue$) 
</select>

ibatis的iterate使用的更多相关文章

  1. ibatis实现Iterate的使用

    <iterate property="" /*可选, 从传入的参数集合中使用属性名去获取值, 这个必须是一个List类型, 否则会出现OutofRangeException, ...

  2. ibatis实现Iterate的使用 (转)

    <iterate         property="" /*可选,              从传入的参数集合中使用属性名去获取值,              这个必须是一 ...

  3. ibatis使用iterate实现批量插入insert正确写法

    由于想批量入库提升效率,最近实现了ibatis的批量插入,结果一直报错 :StringIndexOutOfBoundsException ,原来是value中的格式不正确. 本人邮箱:techqu@1 ...

  4. ibatis中iterate的用法(conjunction="or" ",")

    例子一 查询条件dto public class queryCondition{ private String[] stuIds; private String name;} 查询sqlMap < ...

  5. iBATIS使用$和#的一些理解

    我们在使用iBATIS时会经常用到#这个符号. 比如: sql 代码 select * from member where id =#id# 然后,我们会在程序中给id这个变量传递一个值,iBATIS ...

  6. ibatis遍历数组:ParameterObject or property was not a Collection, Array or Iterator.

    这个问题在使用ibatis的<iterate></iterate>时出现的,很简单,但是蛋疼了很久,记下来 首先从错误提示看,明显意思是你给出ibatis的参数不对路,人家不认 ...

  7. iBatis.net 循环iterate,没有foreach

    3.9.4. Iterate Element This tag will iterate over a collection and repeat the body content for each ...

  8. ibatis<iterate>标签

    <iterate  property="" 从传入的参数集合中使用属性名去获取值,   这个必须是一个List类型,   否则会出现OutofRangeException, ...

  9. 值得注意的ibatis动态sql语法格式

    一.Ibatis常用动态sql语法,简单粗暴用一例子 <select id="iBatisSelectList" parameterClass="java.util ...

随机推荐

  1. 压力测试之TCPP

    1.下载源码 tpcc-mysql-src.tgz 2.解压 tpcc-mysql-src.tgz 3.安装 [root@DBMysql mysql]# cd /home/mysql/tpcc-mys ...

  2. masterha_check_repl报错汇总

    [root@DBMysql ~]#masterha_check_repl --conf=/etc/masterha/app1.cnf 导致如下报错的原因主要有两类: 1.mysql的安装时用源码安装, ...

  3. openerp 经典收藏 记录规则 – 销售只能看到自己的客户,经理可以看到全部(转载)

    记录规则 – 销售只能看到自己的客户,经理可以看到全部 原文地址:http://cn.openerp.cn/record_rule/ OpenERP中的权限管理有四个层次: 菜单级别: 即,不属于指定 ...

  4. 信号驱动的IO

    (1)client1,基于SIGIO的写法: #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h ...

  5. 关于EF分页查询报错(Count must have a non-negative value.)的解决方案

    具体的异常信息如下,一开始没有写日志只看到错误信息:Count must have a non-negative value.,从表面意思可以看出来是Count值出现了负数,所以报错,查了半天的原因也 ...

  6. 九度oj 1523 从上往下打印二叉树

    原题链接:http://ac.jobdu.com/problem.php?pid=1523 建树,再层次遍历bfs.为了找根方便些,加了father指针... 如下: #include<algo ...

  7. 开发移动app与服务器端session的状态管理与交互

    我们进行web开发的时候,一般使用cookie或session来保存用户的登录状态,通过检查cookie或session的数据来验证用户是否具有对某些需要登录的页面的访问权限,这一切都是通过浏览器来完 ...

  8. linq里的select和selectmany操作

    Select() 和 SelectMany() 的工作都是依据源值生成一个或多个结果值.Select() 为每个源值生成一个结果值.因此,总体结果是一个与源集合具有相同元素数目的集合.与之相反,Sel ...

  9. 3-附1 ->和*的区别

    问题: c++ .和 ->有什么区别? 还有什么是继承什么是派生?-------------------------------------------------------------- 比 ...

  10. 54.xilinx_modelsim仿真错误1

    在仿真DDR3核时,用modelsim编译时会出现下面错误 Error:can't read "env(XILINX)":no such variable 原因:在.do文件中指定 ...