Mybaties 实现批量修改

通常我们在做批量更新的时候都会用in 去操作,但in的数据量一上来,就变的缓慢了

修改方案:

<update id="updateShufflingSeq" parameterType="java.util.List">
<foreach collection="list" separator=";" index="index" item="item" open="" close=";">
update t_shuffling set order_seq=#{item.order_seq} where id = #{item.id}
</foreach>
</update>

关键代码就是标黄部分。但很多时候这个语法是在mysql是默认不支持的,只能修改到最后一条数据

我们需要在链接数据库的时候添加  allowMultiQueries=true 这个属性。

最后渲染出来的语句大概是这样的 

update table set xx=xx where xxx= xxx; 

update table set xx=xx where xxx= xxx; 

update table set xx=xx where xxx= xxx; 

update table set xx=xx where xxx= xxx; 

原文地址:https://www.cnblogs.com/memoa/p/10142295.html