item:集合中每个元素进行迭代时的名称
index:表示迭代过程中 每次迭代的位置
open:该语句以什么开始
separator:每次迭代之间用什么分隔符
close:表示以什么结束
collection:此属性必须指定 且有三种形式,如果是传的单参数数组 则在属性中填array,
如果传的是单参数集合List,则在属性中填list ,
如果传的是Map或者实体 则填响应的key值 。
实例:
传入的是一个list,list中是一个个对象。
<foreach item="item" index="index" open="begin" separator=";" close=";end;" collection="list">
update SC_DATA_SOURCE_MONITOR
<set>
FILESTATE = #{item.fileState},
DATASTATE = #{item.dataState},
FILESAVETIME = #{item.fileSaveTime},
FILEYESTERDAY = #{item.fileYesterDay},
DATASAVETIME = #{item.dataSaveTime},
DATAYESTERDAY = #{item.dataYesterDay},
LASTUPDATETIME = #{item.lastupDateTime},
LATELYUPDATETIME = #{item.latelyUpdateTime}
</set>
where TABLENAMES = #{item.tableNames}
</foreach>
传入的是一个list,list中是一Map对象。
<foreach item="item" collection="list" separator=";" open="begin" close=";end;">
insert into sc_monit_exeresult (exe_id,counts,field_code,value) VALUES
(#{item.exeId}, #{item.counts}, #{item.fieldCode}, #{item.value})
</foreach>
<foreach collection="addArray" item="rolePower" separator="UNION ALL">
SELECT
#{updateId},
#{rolePower.menuId},
'1',
'0',
to_number(to_char(sysdate,'yyyymmdd'))
from dual