<!-- 单条数据保存 -->
<insert id="saveOrUpdate" parameterType="TestVo"> insert into table_name ( col1, col2, col3 ) values ( #{field1}, #{field2}, #{field3} ) on duplicate key update col1 = #{field1}, col2 = #{field2}, col3 = #{field3} </insert>
<!-- 批量保存 --> <insert id="batchSaveOrUpdate" parameterType="java.util.List"> insert into table_name ( col1, col2, col3 ) <foreach collection="list" item="item" index="index" separator=","> values ( #{item.field1}, #{item.field2}, #{item.field3} ) </foreach> on duplicate key update col1 = VALUES (col1), col2 = VALUES (col2), col3 = VALUES (col3) </insert>
1
2
本文探讨了数据库操作中的批量保存和更新方法,包括INSERT语句的优化策略,如使用ON DUPLICATE KEY UPDATE,以及如何处理列表参数进行SQL批量插入。适合数据库开发者和IT人员参考。
4455

被折叠的 条评论
为什么被折叠?



