mybatis執行批量更新batch update 的辦法(oracle,mysql兩種)。本站提示廣大學習愛好者:(mybatis執行批量更新batch update 的辦法(oracle,mysql兩種))文章只能為提供參考,不一定能成為您想要的結果。以下是mybatis執行批量更新batch update 的辦法(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" >open</span>=<span class="hljs-string" >"begin"</span> <span class="hljs-keyword" >close</span>=<span class="hljs-string" >"end;"</span> separator=<span class="hljs-string" >";"</span>> <span class="hljs-keyword" >update</span> test <<span class="hljs-keyword" >set</span>> test=${item.test}+<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數據庫采用一下寫法即可執行,但是數據庫銜接必需配置:&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" >open</span>=<span class="hljs-string" >""</span> <span class="hljs-keyword" >close</span>=<span class="hljs-string" >""</span> separator=<span class="hljs-string" >";"</span>> <span class="hljs-keyword" >update</span> test <<span class="hljs-keyword" >set</span>> test=${item.test}+<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兩種),希望對大家有所協助,假如大家有任何疑問請給我留言,會及時回復大家的。在此也十分感激大家對網站的支持!