mybatis batch update mybatis执行批量更新batch update 的方法(oracle,mysql两种)
蜡笔小勋 人气:0想了解mybatis执行批量更新batch update 的方法(oracle,mysql两种)的相关内容吗,蜡笔小勋在本文为您仔细讲解mybatis batch update的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:mybatis,batch,update,下面大家一起来学习吧。
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>
以上所述是小编给大家介绍的mybatis执行批量更新batch update 的方法(oracle,mysql两种),希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
加载全部内容