MyBatis in its argument is an array foreach

First, when there is only one parameter, and this parameter is an array of time

Parameter interface method @Param without adding annotations, collection = "array"

Examples

Interface methods

void deleteMulti(String[] flowerids);

xml file

<delete id="deleteMulti" >
        delete from cart where flower_id in
        <foreach collection="array" item="item" open="(" separator="," close=")">
        #{item}
        </foreach>
</delete>

Second, when there are a plurality of parameters, wherein the array comprises

@Param parameters need to add a comment

Traversing array parameters, collection = "value of the value of annotation array parameter Param"

Examples

Interface methods

void deleteMulti(@Param(value = "names") String[] flowerids,@Param(value = "userid") int userid);

xml file

<delete id="deleteMulti" >
        delete from cart where userid = #{userid} and flower_id in
        <foreach collection="names" item="item" open="(" separator="," close=")">
        #{item}
        </foreach>
</delete>

 

Guess you like

Origin www.cnblogs.com/wei-jing/p/12310281.html