mapper mysl实现批量插入 更新

1.批量插入

<insert id="insertConfirm" parameterType="java.util.List">
insert into `TableName`(id) values
<foreach collection ="list" item="item" index= "index" separator =",">
('${item.id}')
</foreach >
</insert>

2.批量更新
<update id="updateConfirm" parameterType="java.util.List">
   update `TableName`
<trim prefix="set" suffixOverrides=",">
<trim prefix="bgt_stage =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.bgtstage!=null">
when tasktypeid='${i.tasktypeid}' and depcode='${i.depcode}' then
'${i.bgtstage}'
</if>
</foreach>
else bgt_stage
</trim>
<trim prefix=" confirmtime =case" suffix="end,">
<foreach collection="list" item="i" index="index">
<if test="i.confirmtime!=null">
when tasktypeid='${i.tasktypeid}' and depcode='${i.depcode}' then
'${i.confirmtime}'
</if>
</foreach>
else confirmtime
</trim>
</trim>
</update>

trim 属性

prefix:前缀覆盖并增加其内容

suffix:后缀覆盖并增加其内容

prefixOverrides:前缀判断的条件

suffixOverrides:后缀判断的条件

              

原文地址:https://www.cnblogs.com/sx2zx/p/6341020.html