Mybatis批量操作

一、批量更新

1.oracle数据库:

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>

2.mySql数据库

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

例如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true

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

  

posted @ 2016-11-03 16:04  飞翔.  阅读(137)  评论(0编辑  收藏  举报