原文链接: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)

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-03
  • 2022-01-11
猜你喜欢
  • 2021-07-03
  • 2022-01-05
  • 2021-12-09
  • 2022-12-23
  • 2022-12-23
  • 2021-06-26
相关资源
相似解决方案