yankj12 / blog

技术研究、管理实践、其他的一些文章
MIT License
1 stars 2 forks source link

mybatis批量更新 #37

Open yankj12 opened 6 years ago

yankj12 commented 6 years ago

参考自: mybatis学习之路----批量更新数据两种方法效率对比

概述

批量更新数据,实现方式有两种:

for循环语句

注意第一种方法要想成功,需要在db链接url后面带一个参数 &allowMultiQueries=true 即: jdbc:mysql://localhost:3306/mysqlTest?characterEncoding=utf-8&allowMultiQueries=true

for循环加case when

case-when方式具体可以参考下面链接 Mybatis中进行批量更新

结论

直接通过for拼接n条update语句的方式要比case when方式效率要高,尤其是数据量比较大的时候。