How to write the map parameter of the list array passed in by mybatis

Foreach is mainly used to build in conditions. It can iterate a set in SQL statements. The attributes of foreach elements mainly include item, index, collection, open, separator and close. Item indicates the alias of each element in the collection during iteration, index specifies a name, which is used to indicate the location of each iteration in the iteration process, open indicates what the statement starts with, separator indicates what symbol is used as the separator between each iteration, and close indicates what it ends with, When using foreach, the most critical and error prone attribute is the collection attribute, which must be specified, but the value of the attribute is different in different cases. There are three main cases: if the input is a single parameter and the parameter type is a list, the value of the collection attribute is list

If a single parameter is passed in and the parameter type is an array, the attribute value of collection is array

If there are multiple parameters passed in, we need to encapsulate them into a map. Of course, a single parameter can also be encapsulated into a map. In fact, if you pass in a parameter, it will also be encapsulated into a map in mybatis. The key of the map is the parameter name, So at this time, the collection attribute value is the key of the passed in list or array object in its own encapsulated map

Let's practice through code:

data sheet:

HR with Oracle Employees table

Entity: Employees

Mapping file:

Mapper class:

The above description is all about the writing method of mybatis incoming set list array map parameter introduced to you by Xiaobian. I hope it will be helpful to you!

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>