原文鏈接:https://blog.csdn.net/anqinganjie/article/details/84803113
mybatis插入多條數據,若數據庫中存在則更新,若無則插入,具體實例如下:
其中pro_id,day_date為唯一索引
insert into pro(
pro_id,
day_date,
price,
remark
) values
<foreach item="item" index="index" collection="list"
separator=",">
(
#{item.proId,jdbcType=NUMERIC} ,
str_to_date( #{item.dayDate,jdbcType=DATE} , '%Y-%m-%d %h:%i:%s') ,
#{item.price,jdbcType=DECIMAL} ,
#{item.remark,jdbcType=VARCHAR}
)
</foreach>
ON DUPLICATE KEY UPDATE
price = VALUES(price),
remark = VALUES(remark)