Original address: http://www.blogjava.net/kyleYang/archive/2010/02/02/311688.html
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:
[HTML]View Plaincopy
- <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
[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>
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.
Ibatis Iterate label