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)