The foreach tag is primarily used to build in conditions, and he can iterate over the collection in SQL. As follows:
<delete id= "Deletebatch" >
Delete from the user where ID in
<foreach collection= "Array" item= "id" index= "index" open= "(" close= ")" separator= "," >
#{id}
</foreach>
</delete>
If we say that the parameter is----int[] ids = {1,2,3,4,5}----then the following SQL is printed:
Delete form user where ID in (1,2,3,4,5)
Interpretation:
The value of the Collection:collection property is three list, array, map three, respectively, the corresponding parameter type is: List, array, map collection, I passed the argument is an array, so the value is array
Item: Represents an alias for each element during an iteration
Index: Represents the position of each iteration to (subscript) during the iteration
Open: Prefix
Close: Suffix
Separator: delimiter that represents what separates each element in the iteration
We can usually use it for bulk deletions, additions, and so on.
MyBatis use of foreach tags in dynamic sql