mybatis执行批量更新batch update 的方法(oracle,mysql)

oracle和mysql数据库的批量update在mybatis中配置不太一样:


oracle数据库:

  1. <updateidupdateid="batchUpdate" parameterType="java.util.List">  
  2.         
  3.        <foreach collection="list"item="item"index="index"open="begin"close="end;"separator=";">  
  4.                 updatetest  
  5.                 <set>  
  6.                   test=${item.test}+1  
  7.                 </set>  
  8.                 whereid = ${item.id}  
  9.        </foreach>  
  10.             
  11.     </update>  



mysql数据库:


mysql数据库采用一下写法即可执行,但是数据库连接必须配置:&allowMultiQueries=true


例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true
  1. <updateidupdateid="batchUpdate" parameterType="java.util.List">  
  2.         
  3.           <foreach collection="list"item="item"index="index"open=""close=""separator=";">  
  4.                 updatetest  
  5.                 <set>  
  6.                   test=${item.test}+1  
  7.                 </set>  
  8.                 whereid = ${item.id}  
  9.          </foreach>  
  10.             
  11.     </update> 

猜你喜欢

转载自blog.csdn.net/layman1024/article/details/79257853