1.数据库增加uniques
2.mybatis
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="com.example.mapper.TerminalOfflineCountMapper">
<insert id="batchInsertOrUpdate" parameterType="java.util.List">
INSERT INTO terminal_offline_count (t_id, org_id, time, org_name, terminal_type)
VALUES
<foreach collection="list" item="item" separator=",">
(#{item.t_id}, #{item.org_id}, #{item.time}, #{item.org_name}, #{item.terminal_type})
</foreach>
ON CONFLICT (t_id, time) DO UPDATE SET
org_id = EXCLUDED.org_id,
org_name = EXCLUDED.org_name,
terminal_type = EXCLUDED.terminal_type;
</insert>
</mapper>