-- 存在即更新, 不存在就插入 (根据 ID)
- insert into `vclb_mm_inventory` (`ID_`, `STOCK_ID_`, `ITEM_ID_`, `AMOUNT_`)
- values ('489734716803514367', '仓库一', '水杯', 44)
- ON DUPLICATE KEY UPDATE `AMOUNT_` = `AMOUNT_` + 44;
- ---------------------
- <!-- 批量更新数据 -->
- <update id="updateBatch">
- update wd_solr set
- name =
- <foreach collection="list" item="wdSolr" index="index"
- separator="" open="case id"close="end">
- when #{wdSolr.id} then
- #{wdSolr.name}
- </foreach>
- ,logo =
- <foreach collection="list" item="wdSolr" index="index"
- separator="" open="case id"close="end">
- when #{wdSolr.id} then
- #{wdSolr.logo}
- </foreach>
- ,timestamp =
- <foreach collection="list" item="wdSolr" index="index"
- separator="" open="case id"close="end">
- when #{wdSolr.id} then #{wdSolr.timestamp}
- </foreach>
- where id in
- <foreach collection="list" item="wdSolr" index="index"
- separator="," open="(" close=")">
- #{wdSolr.id}
- </foreach>
- </update>
来源: http://www.bubuko.com/infodetail-3109996.html