Mybatis <foreach> Tags

Source: Internet
Author: User

<foreach> tags have the function of looping, which can be used to generate regular SQL statements, and the main attributes are:

Item: Represents the alias at which each element of the collection iterates

Index: Indicates where each iteration is to during the iteration

Open: Indicates what the statement has started

Separator: Indicates what symbol is used to separate each iteration

Close: Indicates what the statement has ended

Collection: Variables that need to be iterated

<SelectID= "Selectpostin"Resulttype= "Domain.blog.Post">SELECT * from POST P WHERE ID in<foreachItem= "Item"Index= "Index"Collection= "List"Open="("Separator=","Close=")">#{item}</foreach></Select>

The functionality of the Foreach element is very powerful, allowing you to specify a collection that declares the collection items and index variables that can be used within the body of the element. It also allows you to specify the opening and closing of a matching string and place the delimiter in the middle of the iteration. This element is very intelligent, so it does not accidentally append extra separators.

Note that you can pass a List instance or array as a parameter object to MyBatis, and when you do, MyBatis will automatically wrap it in a Map with the name key. The list instance will be "list" as the key, and the array instance key will be "array".

To this we have completed a discussion of the XML configuration file and the XML mapping file. The next section explores the Java API in detail so that you can derive maximum benefit from the mappings you have created.

Mybatis <foreach> Tags

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.