mybatis中使用replace into和 insert INTO … ON DUPLICATE KEY UPDATE批量操作

来源:互联网 发布:淘宝图片满了怎么清理 编辑:程序博客网 时间:2024/04/20 06:33

一、replace into

<insert id=“a" useGeneratedKeys="true">REPLACE INTO table_name(product_id,departs_date,price_value)VALUES<foreach collection="list" index="index" item="item"separator=",">(#{item.productId},#{item.departsDate},#{item.priceValue})</foreach></insert>

二、insert INTO … ON DUPLICATE KEY UPDATE

<update id=“b">insert INTO table_name(product_id,departs_date,price_value,)VALUES<foreach collection="list" index="index" item="item"separator=",">(#{item.productId},#{item.departsDate},#{item.priceValue}</foreach> ON DUPLICATE KEY UPDATE  price_type = VALUES(price_type), price_value = VALUES(price_value)</update>

例如:

     insert INTO table_name (product_id,departs_date,price_value,res_id)VALUES(5152760,'2016-11-13','101.00',10014012) ,(5152761,'2016-11-13','102.00',10014012)  ON DUPLICATE KEY UPDATE  price_value=values(price_value);


0 0