1.批量插入:
<insert id="insertRecord">
INSERT INTO tb_record(
detail,
status
) VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.detail},
#{item.status}
)
</foreach>
</insert>
复制代码
2.批量更新:
<update `id`="updateInfo">
UPDATE tb_info
<trim prefix="set" suffixOverrides=",">
<trim prefix="detail =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.detail!=null">
when id=#{item.id} then #{item.detail}
</if>
</foreach>
</trim>
<trim prefix="city =case" suffix="end,">
<foreach collection="list" item="item" index="index">
<if test="item.city!=null">
when id=#{item.id} then #{item.city}
</if>
</foreach>
</trim>
</trim>
WHERE
<foreach collection="list" separator="or" item="item" index="index" >
id=#{item.id}
</foreach>
</update>
复制代码