批量更新update、批量插入insert

1、批量更新update

  int updateBatch(Map<String, Object> m);

  <update id="updateBatch">
    update fc_naturaldanger_item_t
    set checkret_bigd =
    <foreach collection="list" item="item" index="index" separator=" " open="case ID" close="end">
      when #{item.id} then #{item.checkretBigd}
    </foreach>
      where id in
    <foreach collection="list" item="item" index="index" separator="," open="(" close=")">
      #{item.id,jdbcType=INTEGER}
    </foreach>
  </update>

2、批量插入insert

  int insertBath(Map<String, Object> m);

  <insert id="insertBath">
    insert into fc_naturaldanger_item_t (dangerstudyid,dangerid, checkret)
    values 
    <foreach collection="list" item="item" separator=",">
      (#{dangerstudyid}, #{item.dangerid}, #{item.checkret})
    </foreach>
  </insert>        //id为自增长状态
我驰骋天下,守你盛世繁华
原文地址:https://www.cnblogs.com/lotuses/p/11356052.html