oracle和mysql数据库的批量update在mybatis中配置不太一样:
oracle数据库:[codesyntax lang="java"]
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="begin" close="end;" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>[/codesyntax]
mysql数据库:
mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true
例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&characterEncoding=UTF-8&allowMultiQueries=true
[codesyntax lang="java"]
<update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" index="index" open="" close="" separator=";"> update test <set> test=${item.test}+1 </set> where id = ${item.id} </foreach> </update>[/codesyntax]
查看原文:http://surenpi.com/2016/08/16/mybatis%e6%89%a7%e8%a1%8c%e6%89%b9%e9%87%8f%e6%9b%b4%e6%96%b0batch-update-%e7%9a%84%e6%96%b9%e6%b3%95%ef%bc%88oraclemysql%ef%bc%89/
