mybatis中的foreach


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
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值