ibatis的iterate使用
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使用的更多相关文章
- ibatis实现Iterate的使用
<iterate property="" /*可选, 从传入的参数集合中使用属性名去获取值, 这个必须是一个List类型, 否则会出现OutofRangeException, ...
- ibatis实现Iterate的使用 (转)
<iterate property="" /*可选, 从传入的参数集合中使用属性名去获取值, 这个必须是一 ...
- ibatis使用iterate实现批量插入insert正确写法
由于想批量入库提升效率,最近实现了ibatis的批量插入,结果一直报错 :StringIndexOutOfBoundsException ,原来是value中的格式不正确. 本人邮箱:techqu@1 ...
- ibatis中iterate的用法(conjunction="or" ",")
例子一 查询条件dto public class queryCondition{ private String[] stuIds; private String name;} 查询sqlMap < ...
- iBATIS使用$和#的一些理解
我们在使用iBATIS时会经常用到#这个符号. 比如: sql 代码 select * from member where id =#id# 然后,我们会在程序中给id这个变量传递一个值,iBATIS ...
- ibatis遍历数组:ParameterObject or property was not a Collection, Array or Iterator.
这个问题在使用ibatis的<iterate></iterate>时出现的,很简单,但是蛋疼了很久,记下来 首先从错误提示看,明显意思是你给出ibatis的参数不对路,人家不认 ...
- iBatis.net 循环iterate,没有foreach
3.9.4. Iterate Element This tag will iterate over a collection and repeat the body content for each ...
- ibatis<iterate>标签
<iterate property="" 从传入的参数集合中使用属性名去获取值, 这个必须是一个List类型, 否则会出现OutofRangeException, ...
- 值得注意的ibatis动态sql语法格式
一.Ibatis常用动态sql语法,简单粗暴用一例子 <select id="iBatisSelectList" parameterClass="java.util ...
随机推荐
- Win10下IIS配置图解、MVC项目发布图解、IIS添加网站图解
Win10下IIS配置 .找到控制面板:[开始]菜单鼠标右击,打开[控制面板] .打开控制面板,点击[程序],点击[启用或关闭Windows功能] 下一步,点击[启用虎关闭Windows功能] . 开 ...
- 03-树3 Tree Traversals Again
二叉树及其遍历 push为前序遍历序列,pop为中序遍历序列.将题目转化为已知前序.中序,求后序. 前序GLR 中序LGR 前序第一个为G,在中序中找到G,左边为左子树L,右边为右子树R. 将左右子树 ...
- html/css 盒子布局 Margin 、Padding 、border 以及 清除浮动的知识 (学习HTML过程中的小记录)
html/css 盒子布局 Margin .Padding .border 以及 清除浮动的知识 (学习HTML过程中的小记录) 作者:王可利(Star·星星) width 是"宽 ...
- PBOC规范(2.0->3.0)对照表
1 数据方面 TAG PBOC2.0 ...
- hdu 2034 人见人爱A-B
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=2034 人见人爱A-B Description 参加过上个月月赛的同学一定还记得其中的一个最简单的题目, ...
- locate 命令
ac OS X 下的 locate 在便利性上差了一些.主要是一些辅助工具.我在开始用 Mac OS X 下的locate 时,把过去知道的创立数据库的命令尝试了个遍,就是没有可行的.后来搜索网络才找 ...
- MySQL 触发器简单实例
~~语法~~ CREATE TRIGGER <触发器名称> --触发器必须有名字,最多64个字符,可能后面会附有分隔符.它和MySQL中其他对象的命名方式基本相象.{ BEFORE | ...
- [转]ubuntu 10.04下的配置tftp服务器
[转]ubuntu 10.04下的配置tftp服务器 http://www.cnblogs.com/geneil/archive/2011/11/24/2261653.html 第1步:安装tftp所 ...
- Python 抓取网页乱码问题 以及EXCEL乱码
import codecs f1=codecs.open('items.json', 'r', encoding='utf-8').read().decode("unicode_escape ...
- Android实现SQLite数据库联系人列表
Android实现SQLite数据库联系人列表 开发工具:Andorid Studio 1.3 运行环境:Android 4.4 KitKat 工程内容 实现一个通讯录查看程序: 要求使用SQLite ...