Mybatis 批量更新失败,单条成功
2017-08-28 14:16
162 查看
Mybatis 批量更新失败,单条成功
在项目开发过程中,结合业务场景,需要对某个表进行批量更新,完成所有的业务代码和Mybatis XML文件后,单元测试时,发现调用批量更新只有一条记录时,执行成功,传入多条记录,进行批量更新时,则提示失败,错误信息如下:org.springframework.jdbc.BadSqlGrammarException: ### Error updating database. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '...... ### The error may involve .... ### The error occurred while setting parameters ### SQL:
其中XML映射批量更新的结构如下:
<!-- 批量更新 --> <update id="batchUpdate" parameterType="java.util.List"> <foreach collection="list" item="item" separator=";"> update xxxxxx <set> <if test="item.xxx!= null"> xxx= #{item.xxx,jdbcType=BIGINT}, </if> ...... </set> where id =#{item.id} </foreach> </update>
经过代码排查,以及批量update语句通过SQL工具直接执行均能成功,排除代码和sql语句问题,最后求助Google大神,发现使用mybatis进行批量插入与更新时,必须在配置连接url时指定allowMultiQueries=true
mysql.db.url=jdbc:mysql://127.0.0.1:3306/test?useUnicode=true&characterEncoding=UTF-8&zeroDateTimeBehavior=convertToNull&&allowMultiQueries=true
经测试,完美解决此问题。
相关文章推荐
- 【mybatis】批量更新失败
- Mybatis根据id批量更新
- 单条/批量增加信息,Spring MVC, Mybatis, MySQL
- Mybatis之批量更新操作
- Mybatis的批量添加和批量更新
- mybatis--mysql 批量插入批量更新在一条sql语句中完成
- mybatis执行批量更新batch update 的方法
- mybatis 批量插入 ,更新总结
- mybatis执行批量更新update 的方法oracle小记
- mybatis 批量更新update详解
- mybatis执行批量更新update
- Java--批量插入更新在一条sql里解决-mybatis-mysql-联合主键(建立唯一索引)
- mybatis批量新增,更新的一些问题
- mybatis的批量更新实例
- Mybatis之多种数据类型的批量的更新数据库表
- 【mybatis之批量更新】
- mybatis XML中批量更新值
- mybatis 的批量操作,查询、更新、插入
- 盗版WindowsServer不能更新powershell,用老的自带函数批量下载总是失败?
- mybatis 注解的方式批量插入,更新数据