MyBatis the action of the key value in the batch map as List

Source: Internet
Author: User

There are three types of foreach, respectively, list,[] (array), map three species.

The first of the foreach is used to place the list and array.


The following table is the purpose and the point of attention of the various attributes I have summarized. foreach Property

Property Description
Item The concrete object in the loop body. Supports point path access for properties, such as Item.age,item.info.details.
Specify: In the list and array is the object, in the map is value.
This parameter is required.
Collection To make a Foreach object, the,list<?> object defaults to the List as the key, and the array object has an array instead of the key, and the map object is replaced by a map as the key.
Of course, you can use @param ("KeyName") to set the key as an incoming parameter, after setting the KeyName, List,array,map will be invalidated. In addition to the participation in this case, there is a time for a field that is a parameter object. As an example:
If user has attribute list IDs. The Enter parameter is a user object, then this collection = "IDs"
If the user has attributes IDs IDs, where IDs is an object, IDS has a property list ID, and the Enter parameter is a user object, then collection = "Ids.id"
The above is just an example, the concrete collection equals what, depends on you want to do the cycle of that element.
This parameter is required.
Separator The delimiter between elements, for example, when in (), separator= "," is automatically separated by "," in the element, avoiding the manual entry of commas that causes SQL errors, such as in (1, 2,). This parameter is optional.
Open The start symbol for the foreach code, typically (and close= ")" is shared. Commonly used in (), values (). This parameter is optional.
Close The close symbol for the foreach code, generally, is the "open=" ("Shared"). Commonly used in (), values (). This parameter is optional.
Index In the list and array, index is the ordinal of the element, and in the map, index is the key of the element, which is optional.

Service

Public message Allsavereservation (privatebrandentity Main, list<privatebrandentity> items) {

MAP params = new HashMap ();

Params.put ("Djh", DJH);

Params.put ("Items", items);

SAVERESERVATIONCB (params);

}

DAO mapper layer maintained with SAVERESERVATIONCB (params);

Mapper.xml

<!--Insert Table data-->
<insert id= "SAVERESERVATIONCB"parametertype= "Java.util.Map">
INSERT INTO Yyzy. T_YYZY_ZYPP_YL_CB (ZBDM, YYDM, Yypc, Yljs, Yyzl, MJJZ, YYNF, YYCDDM, YYDJDM, YYLBDM, YYKBDM, YYBZDM)
With Yyxx (YYNF,YYCDDM,YYDJDM,YYLBDM,YYKBDM,YYBZDM,YYPC,YLJS) as
(
VALUES

<foreach collection="Items"Item= "Item" separator= "," >
(#{item.yynf},#{item.yycddm},#{item.yydjdm},#{item.yylbdm},#{item.yykbdm},#{item.yybzdm},#{item.yypc},#{ ITEM.YLJS})
</foreach>
)

, TB_ZBDM as (
Select ZBDM
From Yyzy. T_yyzy_zypp_yl_zb
where djh=#{djh, Jdbctype=varchar}
Group BY ZBDM)

Select B.ZBDM, D.YYDM, A.yypc, A.yljs, C.gjmj*a.yljs as Yyzl, c.gjmj as MJJZ, A.YYNF, D.yycdbs, D.yydjbs, D.yylbbs, D.YYKB BS, A.YYBZDM
From Yyxx as a
Left Join TB_ZBDM as B
On 1=1
Left join DIM. T_DIM_YYZY_GJMJ as C
On A.YYLBDM=C.YYLBDM
and A.YYKBDM=C.YYKBDM
Left join Yyzy. T_yyzy_yyzdbmx_7 as D
On A.YYCDDM=D.YYCDDM
and A.YYDJDM=D.YYDJDM
and A.YYLBDM=D.YYLBDM
and A.YYKBDM=D.YYKBDM
and A.YYNF=D.YYNF
and A.yypc=d.yypc
</insert>



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.