一、批量插入
<insert id="insert" parameterType="list">
insert into aaa(
id,
name,
create_time,
update_time,
create_user,
update_user)
VALUES
<foreach collection ="list" item="bbb" separator =",">
(
#{bbb.id},
#{bbb.name},
#{bbb.create_time},
#{bbb.update_time},
#{bbb.create_user},
#{bbb.update_user}
)
</foreach >
</insert>
二、批量更新
<update id="methodName" parameterType="list">
update ccc
<trim prefix="set" suffixOverrides=",">
<trim prefix="student_status =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<!--studentStatus 字段 更新 -->
<if test="item.studentStatus !=null and item.studentStatus != ''">
when id=#{item.id} then #{item.studentStatus}
</if>
</foreach>
</trim>
<trim prefix="name =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<!--name 字段跟新 -->
<if test="item.name !=null and item.name != ''">
when id=#{item.id} then #{item.name}
</if>
</foreach>
</trim>
</trim>
where id in
<foreach collection="list" index="index" item="item" separator="," open="(" close=")">
#{item.id,jdbcType=BIGINT}
</foreach>
</update>