mybatis执行批量更新batch update 的方法

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

oracle数据库:mysql

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

mysql数据库:sql

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

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

必定要加这个,否则抱错,即便语句复制出来正确执行,系统仍是会抱错oracle

<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>
相关文章
相关标签/搜索