目录
1、foreach属性
- collection:必填,值为要迭代循环的属性名。
- item:变量名,值为从迭代对象中取出的每一个值。
- index:索引的属性名,在集合数组情况下为当前索引值,当迭代循环的对象是 Map类型时,这个值为 Map的key。
- open:整个循环开头的字符串。
- close:整个循环内容结尾的字符串。
- separator:每次循环的分隔符
2、foreach 实现 in 集合
<select>
select * from table
where id in
<foreach collection="list" open="(" close=")" separator="," item="id" index="i">
#{id}
</foreach>
</select>
3、foreach 实现 批量插入
<insert>
insert into table (a1, a2) values
<foreach collection="list" separator="," item="item">
( #{item.a1}, #{item.a2} )
</foreach>
</insert>
4、foreach 实现动态 update
<update>
update table
set
<foreach collection="_paramter" separator="," item="val" index="key">
#{key} = #{val} )
</foreach>
where id=#{id}
</update>