码迷,mamicode.com
首页 > 数据库 > 详细

mybatis执行批量更新batch update 的方法(oracle,mysql)

时间:2020-05-27 15:29:53      阅读:108      评论:0      收藏:0      [点我收藏+]

标签:bsp   upd   ali   必须   color   sql   cti   jdb   line   

有时候oracle的最后一个sql少个分号,要在end前面加上分号
 
oracle和mysql数据库的批量update在mybatis中配置不太一样:
oracle数据库:
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>
mysql数据库:
mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>

mybatis执行批量更新batch update 的方法(oracle,mysql)

标签:bsp   upd   ali   必须   color   sql   cti   jdb   line   

原文地址:https://www.cnblogs.com/zhuyeshen/p/12972902.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!