ibatis实现Iterate的使用

<iterate

property=""   /*可选,   从传入的参数集合中使用属性名去获取值,   这个必须是一个List类型,   否则会出现OutofRangeException,   通常是参数使用java.util.Map时才使用,  如果传入的参数本身是一个java.util.List, 不能只用这个属性.    /

conjunction="" /*可选,    iterate可以看作是一个循环,   这个属性指定每一次循环结束后添加的符号,   比如使每次循环是OR的, 则设置这个属性为OR*/

open="" /*可选, 循环的开始符号*/

close="" /*可选, 循环的结束符号*/

prepend="" /*可选, 加在open指定的符号之前的符号*/

>

1.查询

<!-- Iterate的使用,根据多个匹配条件查询,类似in(a,b,c)-->

<select id="selectByIterate" parameterClass="java.util.List" resultClass="user">

SELECT * FROM USERS WHERE USER_ID IN

<iterate conjunction="," open="(" close=")">

#ids[]#

</iterate>

</select>

注意:不要property属性,否则报错。String index out of range: -1

2. 但是,若参数有多个传入的一个是List,另一个不是, parameterClass为map时,需要property属性区分要遍历的  集合。

2.删除

<!-- 批量删除对象的时候,iterate不要property属性 -->

<delete id="delStudybook" parameterClass="java.util.List">

delete FROM STUDYBOOK WHERE ID IN

<iterate conjunction="," open="(" close=")">

#bookList[]#

</iterate>

</delete>

http://hongzhguan.iteye.com/blog/1222353

时间: 2024-08-26 15:06:00

ibatis实现Iterate的使用的相关文章

ibatis的iterate使用

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

ibatis实现Iterate的使用 (转)

<iterate         property="" /*可选,              从传入的参数集合中使用属性名去获取值,              这个必须是一个List类型,              否则会出现OutofRangeException,              通常是参数使用java.util.Map时才使用,              如果传入的参数本身是一个java.util.List, 不能只用这个属性.             不知道为啥

ibatis中iterate的用法(conjunction=&quot;or&quot; &quot;,&quot;)

例子一 查询条件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 <

ibatis iterate 使用

(转)ibatis实现Iterate的使用 源自:http://hongzhguan.iteye.com/blog/1222353 <iterate property="" /*可选, 从传入的参数集合中使用属性名去获取值, 这个必须是一个List类型, 否则会出现OutofRangeException, 通常是参数使用java.util.Map时才使用, 如果传入的参数本身是一个java.util.List, 不能只用这个属性. 不知道为啥官网: http://ibatis.a

iBatis.net 循环iterate,没有foreach

3.9.4. Iterate Element This tag will iterate over a collection and repeat the body content for each item in a List 3.9.4.1. Iterate Attributes: prepend – the overridable SQL part that will be prepended to the statement (optional) property – a propert

ibatis iterate标签

原文地址:http://www.blogjava.net/kyleYang/archive/2010/02/02/311688.html Iterate:这属性遍历整个集合,并为 List 集合中的元素重复元素体的内容. Iterate 的属性:       prepend  - 可被覆盖的 SQL 语句组成部分,添加在语句的前面(可选)       property  - 类型为 java.util.List 的用于遍历的元素(必选)       open  -  整个遍历内容体开始的字符串,

ibatis 动态SQL

直接使用JDBC一个非常普遍的问题就是动态SQL.使用参数值.参数本身和数据列都是动态SQL,通常是非常困难的.典型的解决办法就是用上一堆的IF-ELSE条件语句和一连串的字符串连接.对于这个问题,Ibatis提供了一套标准的相对比较清晰的方法来解决一个问题,这里有个简单的例子: <select id="getUserList" resultMap="user"> select * from user <isGreaterThan prepend=

ibatis mybatis传入List参数

--ibatis <select id="getWzlb" parameterClass="map" resultClass="java.util.HashMap"> select ... from wz09 where 1=1 <isNotEmpty prepend="AND" property="ids"> <!-- ids是map的一个key --> id in &

iBatis的基本使用

数据库连接信息:db.properties driverClass=com.mysql.jdbc.Driverurl=jdbc:mysql://localhost:3306/ssiusername=rootpassword=123456 主配置文件:sqlMapConfig.xml 1 <?xml version="1.0" encoding="utf-8"?> 2 <!DOCTYPE sqlMapConfig 3 PUBLIC "-//