Iterate use of Ibatis

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.