MySQL:ON DUPLICATE KEY UPDATE
参考 https://blog.csdn.net/qq_2277…
PostgreSQL:ON CONFLICT
参考 https://blog.csdn.net/weixin_…
MyBatis:
<selectKey keyProperty="count" resultType="int" order="BEFORE">
select count(1) as count from xxx where aaa=1
</selectKey>
<if test="count > 0">
update set xxx
</if>
<if test="count == 0">
INSERT INTO xxx
</if>
Ps:MyBatis 的形式在遇到并发插入报反复 key 时,能够用重试的形式解决