省略service层、mapper层,动态sql语句如下
<insert id="batchUpsert">
INSERT INTO map_t_collection (id, column1, column2, column3, create_time, latest_update_time)
VALUES
<foreach collection="list" item="item" index="index" separator=",">
(#{item.id}, #{item.value1}, #{item.value2}, #{item.value3}, now(), now())
</foreach>
ON CONFLICT(id) DO UPDATE SET
column1 = EXCLUDED.column1, column2 = EXCLUDED.column2, column3= EXCLUDED.column3, latest_update_time =
EXCLUDED.latest_update_time
</insert>
注: 其中id为唯一约束主键,每次覆盖更新只更新最近修改时间,不更新创建时间