先上例子
比如这里我传入一个待删除的id的list
void deleteByTidList(@Param("tidList") List<Integer> tidList);
<delete id="deleteByTidList">
delete from train
where id in
<foreach collection="tidList" open="(" close=")" separator="," item="tid">
#{tid}
</foreach>
</delete>
后看理论
foreach元素的属性以下几个
-
item:集合中元素迭代时的别名,该参数为必选。
-
index:在list和数组中,index是元素的序号,在map中,index是元素的key,该参数可选
-
open:foreach代码的开始符号,一般是(和close=")"合用。常用在in(),values()时。该参数可选
-
separator:元素之间的分隔符
-
close: foreach代码的关闭符号,一般是)和open="("一起使用
-
collection: 要做foreach的对象