Ibatis Iterate label

Source: Internet
Author: User

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
    1. <iterate prepend= "and" property= "usernamelist"
    2. Open= "(" close= ")" conjunction= "OR">
    3. Username= #userNameList []#
    4. </Iterate>


How to configure the in statement in Ibatis needs to be iterated, not directly using string notation

[HTML]View Plaincopy
  1. <select id="sql_test" parameterclass="Myprambean" resultclass= "myresult">
  2. Select *from tablewhere name in
  3. <iterate property="IDs" conjunction="," close=")" open="(" / >
  4. #ids []#
  5. </Iterate>
  6. and code= #code #
  7. </Select>

[Java]View Plaincopy
    1. Myprambean
    2. {
    3. Private String Code;
    4. Private List IDs;
    5. ...
    6. }


eg

[HTML]View Plaincopy
  1. <delete id= "member.batchdelete" parameterclass="java.util.List">
  2. DELETE from member where ID in
  3. <iterate conjunction="," open="(" close=")" >
  4. #value []#
  5. </Iterate>
  6. </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

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.