mysql数据库,使用mybatis进行批量更新

环境:

db:mysql5.6.22
mybatis:3.4.5


动态拼接成:

update xx set xx=xx;

update xx set xx=xx;

update xx set xx=xx;

这种形式的去进行批量更新操作

注:使用这种方式需要在jdbc:mysql://xx.xx.xx.xx:3306/db_name?配置下加上参数allowMultiQueries=true(allowMultiQueries区分大小写)
即:jdbc:mysql://xx.xx.xx.xx:3306/db_name?allowMultiQueries=true
    
mapper.xml中

<update id="updateList" parameterType="java.util.List">
	<foreach close=";" collection="list" index="index" item="test" open="" separator=";">
		update t_test
		<set>
			<if test="test.name!=null">
				name=#{test.name,jdbcType=VARCHAR},
			</if>
			<if test="test.sex!=null">
				sex=#{test.sex,jdbcType=VARCHAR},
			</if>
		</set>
		where id=#{test.id}
	</foreach>
</update>

猜你喜欢

转载自blog.csdn.net/csdn15679160266/article/details/85160035