mybatis执行批量更新batch update 的方法
Oracle和MySQL数据库的批量update在mybatis中配置不太一样:oracle数据库:?1234567891011updateid="batchUpdate" parameterType="java.util.List">
·
Oracle和MySQL数据库的批量update在mybatis中配置不太一样:
oracle数据库:
|
1
2
3
4
5
6
7
8
9
10
11
|
< 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&characterEncoding=UTF-8&allowMultiQueries=true
|
1
2
3
4
5
6
7
8
9
10
11
|
< 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 >
|
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐

所有评论(0)