Iterate: This property iterates through the collection and repeats the contents of the element body for the elements in the list collection.
Properties of the iterate:
Prepend-an element of the SQL statement that can be overwritten, added in front of the statement (optional)
Property-element of type java.util.List for traversal (required)
Open-a string that begins with the entire traversed content body, which defines parentheses (optional)
Close-the entire string that iterates through the body of the content, used to define parentheses (optional)
conjunction-a string between each iteration of the content used to define and or or (optional)
Iterates over an element of type java.util.List.
Example:
<iterate prepend= "and" property= "Usernamelist"
Open= "(" close= ")" conjunction= "OR" >
Username= #userNameList []#
</iterate>
How to configure the in statement in Ibatis needs to be iterated, not directly using string notation
<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>
Note:When using <iterate>, it is important to include square brackets [] After the list element name, and square brackets [] will
The object is labeled list to prevent the parser from simply outputting the list as a string.
Posted on 2010-02-02 15:49 Flying Bear Read (20034) Comments (3) Edit favorite Category: Ibatis
Comments # Re:ibatis Iterate using 2011-10-06 01:10 wiky
How to configure the in statement in Ibatis needs to be iterated, not directly using string notation
<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 []# to change to #ids[]#. Reply to more comments
# Re:ibatis's iterate use [not logged in] 2013-08-22 13:36 hehe
The third type: In the back of the data is determined, using string to pass in
<select id= "Getemaillist_test2" parameterclass= "Testin" resultclass= "Emailinfo_" >
SELECT *
From Mailinfo with (NOLOCK)
where ID in
($StrValue $)
</select>
Iterate use of Ibatis