首页 > 数据库技术 > 详细

mysql中Mybatis批量update需要新添加配置allowMultiQueries=true

时间:2021-06-12 11:16:01      阅读:28      评论:0      收藏:0      [点我收藏+]

mysql默认不支持批量update,在项目中使用了批量update,一直报错。mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true

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>

————————————————

mysql中Mybatis批量update需要新添加配置allowMultiQueries=true

原文:https://www.cnblogs.com/zhonggongjavastudy/p/14877810.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!