Method for mybatis to perform batch update of batch update (oracle mysql)

  • 2020-05-27 05:40:24
  • OfStack

The batch update of Oracle and MySQL databases is configured differently in mybatis:

oracle database:


<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 database:

The mysql database can be executed as follows, but the database connection must be configured: & allowMultiQueries=true

For example: jdbc: mysql: / / 192.168.1.236:3306 / test & # 63; useUnicode = true & amp;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> 

Related articles: