mybatis执⾏批量更新batchupdate的⽅法(oracle,mysql两种)
Oracle和MySQL数据库的批量update在mybatis中配置不太⼀样:
oracle数据库:
<code class="hljs tcl" ><<span class="hljs-keyword" >update</span> id=<span class="hljs-string" >"batchUpdate"</span> parameterType=<span class="hljs-string" >"java.util.List"</span>>
<<span class="hljs-keyword" >foreach</span> collection=<span class="hljs-string" >"list"</span> item=<span class="hljs-string" >"item"</span> index=<span class="hljs-string" >"index"</span> <span class="hljs-keyword"        <span class="hljs-keyword" >update</span> test
<<span class="hljs-keyword" >set</span>>
test=${st}+<span class="hljs-number" >1</span>
</<span class="hljs-keyword" >set</span>>
where id = ${item.id}
</<span class="hljs-keyword" >foreach</span>>
</<span class="hljs-keyword" >update</span>></code>
mysql数据库:
mysql数据库的方法
mysql数据库采⽤⼀下写法即可执⾏,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
<code class="hljs tcl" ><<span class="hljs-keyword" >update</span> id=<span class="hljs-string" >"batchUpdate"</span> parameterType=<span class="hljs-string" >"java.util.List"</span>>
<<span class="hljs-keyword" >foreach</span> collection=<span class="hljs-string" >"list"</span> item=<span class="hljs-string" >"item"</span> index=<span class="hljs-string" >"index"</span> <span class="hljs-keyword"        <span class="hljs-keyword" >update</span> test
<<span class="hljs-keyword" >set</span>>
test=${st}+<span class="hljs-number" >1</span>
</<span class="hljs-keyword" >set</span>>
where id = ${item.id}
</<span class="hljs-keyword" >foreach</span>>
</<span class="hljs-keyword" >update</span>></code>
以上所述是⼩编给⼤家介绍的mybatis执⾏批量更新batch update 的⽅法(oracle,mysql两种),希望对⼤家有所帮助,如果⼤家有任何疑问请给我留⾔,⼩编会及时回复⼤家的。在此也⾮常感谢⼤家对
⽹站的⽀持!

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。