Mapper.xml in foreach

Foreach tag reference for the interpretation of the information online, as follows:

foreach is mainly used in building in conditions that can be iterated in a set of SQL statements.

Foreach element attribute mainly item, index, collection, open, separator, close.

item: indicates the alias iterate each element in the collection

index: Specify a name to represent the iterative process, each iteration to the position

open: What indicates that the statement to begin

separator: iterating between each represents what symbol as a delimiter

close: what is expressed in the end

When using foreach of the most critical and most error-prone is a collection property, which must be specified, but under different circumstances, the value of the property is not the same, there are about three cases:

 

1. If one parameter is passed in the parameter type is a List and time, collection attribute value list

2. If one parameter is passed and the time parameter is an array type array, collection attribute value array

3. If the argument passed is more, we need to package them into a Map, of course, can also be packaged as a single parameter map

Reference Code:

1、List

When the argument is an object, collection = "object variable name"


When the parameter is of type list, collection = "list"


insert into student_questions(mkId,queId)
values

(#{item.mkId,jdbcType=VARCHAR},#{item.queId,jdbcType=VARCHAR})


2、Integer[]


 3、Map<String,List >


Note: studentLessonIds as a key value

Original link: https://blog.csdn.net/sunshine_yg/article/details/80271970

Guess you like

Origin www.cnblogs.com/ncwoniu/p/12016600.html