ibatis iterate标签
2015-06-30 08:33
218 查看
原文地址:http://www.blogjava.net/kyleYang/archive/2010/02/02/311688.html
Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。
Iterate 的属性:
prepend - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选)
property - 类型为 java.util.List 的用于遍历的元素(必选)
open - 整个遍历内容体开始的字符串,用于定义括号(可选)
close -整个遍历内容体结束的字符串,用于定义括号(可选)
conjunction - 每次遍历内容之间的字符串,用于定义 AND 或 OR(可选)
遍历类型为 java.util.List的元素。
例子:
[html] view plaincopy
<iterate prepend=”AND” property=”userNameList”
open=”(” close=”)” conjunction=”OR”>
username=#userNameList[]#
</iterate>
ibatis中如何配置in语句,需要迭代,不能直接用string的写法
[html] view plaincopy
<select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
select *from tablewhere name in
<iterate property="ids" conjunction="," close=")" open="(" />
#ids[]#
</iterate>
and code=#code#
</select>
[java] view plaincopy
myPramBean
{
private String code;
private List ids;
...
}
eg:
[html] view plaincopy
<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。
Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容。
Iterate 的属性:
prepend - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选)
property - 类型为 java.util.List 的用于遍历的元素(必选)
open - 整个遍历内容体开始的字符串,用于定义括号(可选)
close -整个遍历内容体结束的字符串,用于定义括号(可选)
conjunction - 每次遍历内容之间的字符串,用于定义 AND 或 OR(可选)
遍历类型为 java.util.List的元素。
例子:
[html] view plaincopy
<iterate prepend=”AND” property=”userNameList”
open=”(” close=”)” conjunction=”OR”>
username=#userNameList[]#
</iterate>
ibatis中如何配置in语句,需要迭代,不能直接用string的写法
[html] view plaincopy
<select id="sql_test" parameterclass="myPramBean" resultclass="myResult">
select *from tablewhere name in
<iterate property="ids" conjunction="," close=")" open="(" />
#ids[]#
</iterate>
and code=#code#
</select>
[java] view plaincopy
myPramBean
{
private String code;
private List ids;
...
}
eg:
[html] view plaincopy
<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。
相关文章推荐
- mkdir的参数-p的作用
- Android学习笔记----Java字符串MD5加密
- Material UI:非常强大的CSS框架
- EasyUIControl(一个可以简化ui界面的组件库
- 线程同步-互斥对象
- 文件共享服务器搭建
- C语言控制台打印3D爱心图案
- IBATIS中的include功能
- 舵机的工作原理
- css笔记05:表单
- 腾讯产品总监蒋宁:对产品经理的深入理解及建议
- Python-lamada表达式
- Android学习笔记----Java中的字符串比较
- python装饰器
- 重踏学习Java路上_Day13(StringBuffer,Array与数组,Integer,Character,装箱,拆箱)
- FTP服务器的搭建
- 机器学习实战——第十三/十四章:利用PCA和SVD来简化数据
- 奇酷乐三角恋的背后,小三上位or内部不和?
- Windows7下无法禁用网络连接的问题
- 【剑指Offer学习】【面试题22:栈的压入、弹出序列】