mybatis执行批量更新batch update 的方法(oracle,mysql两种)
时间:2020-11-08 12:56:46|栏目:JAVA代码|点击: 次
Oracle和MySQL数据库的批量update在mybatis中配置不太一样:
oracle数据库:
<code class="hljs tcl" style=""><<span class="hljs-keyword" style="">update</span> id=<span class="hljs-string" style="">"batchUpdate"</span> parameterType=<span class="hljs-string" style="">"java.util.List"</span>> <<span class="hljs-keyword" style="">foreach</span> collection=<span class="hljs-string" style="">"list"</span> item=<span class="hljs-string" style="">"item"</span> index=<span class="hljs-string" style="">"index"</span> <span class="hljs-keyword" style="">open</span>=<span class="hljs-string" style="">"begin"</span> <span class="hljs-keyword" style="">close</span>=<span class="hljs-string" style="">"end;"</span> separator=<span class="hljs-string" style="">";"</span>> <span class="hljs-keyword" style="">update</span> test <<span class="hljs-keyword" style="">set</span>> test=${item.test}+<span class="hljs-number" style="">1</span> </<span class="hljs-keyword" style="">set</span>> where id = ${item.id} </<span class="hljs-keyword" style="">foreach</span>> </<span class="hljs-keyword" style="">update</span>></code>
mysql数据库:
mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
<code class="hljs tcl" style=""><<span class="hljs-keyword" style="">update</span> id=<span class="hljs-string" style="">"batchUpdate"</span> parameterType=<span class="hljs-string" style="">"java.util.List"</span>> <<span class="hljs-keyword" style="">foreach</span> collection=<span class="hljs-string" style="">"list"</span> item=<span class="hljs-string" style="">"item"</span> index=<span class="hljs-string" style="">"index"</span> <span class="hljs-keyword" style="">open</span>=<span class="hljs-string" style="">""</span> <span class="hljs-keyword" style="">close</span>=<span class="hljs-string" style="">""</span> separator=<span class="hljs-string" style="">";"</span>> <span class="hljs-keyword" style="">update</span> test <<span class="hljs-keyword" style="">set</span>> test=${item.test}+<span class="hljs-number" style="">1</span> </<span class="hljs-keyword" style="">set</span>> where id = ${item.id} </<span class="hljs-keyword" style="">foreach</span>> </<span class="hljs-keyword" style="">update</span>></code>
上一篇:浅谈对java中锁的理解
栏 目:JAVA代码
本文标题:mybatis执行批量更新batch update 的方法(oracle,mysql两种)
本文地址:http://www.codeinn.net/misctech/20508.html
阅读排行
- 1Java Swing组件BoxLayout布局用法示例
- 2java中-jar 与nohup的对比
- 3Java邮件发送程序(可以同时发给多个地址、可以带附件)
- 4Caused by: java.lang.ClassNotFoundException: org.objectweb.asm.Type异常
- 5Java中自定义异常详解及实例代码
- 6深入理解Java中的克隆
- 7java读取excel文件的两种方法
- 8解析SpringSecurity+JWT认证流程实现
- 9spring boot里增加表单验证hibernate-validator并在freemarker模板里显示错误信息(推荐)
- 10深入解析java虚拟机