mybatis批量更新(update foreach)失败
2017-05-18 11:36
375 查看
最近做项目需要一个很奇葩的现象,项目是spring+springMvc+mybatis ,在本地进行批量更新时是成功的,但上到线上环境就一直报错,代码如下:
<!--批量更新报表 -->
<update id="updateIssueByBatch" parameterType="java.util.List">
<foreach collection="issueList" item="item" index="index" separator=";">
update sys_issue
<set>
<if test="item.first != null and item.first != ''">first_class = #{item.first}, </if>
<if test="item.second != null and item.second != ''">second_class = #{item.second}, </if>
updated_time = now()
</set>
where id = #{item.Id}
</foreach>
</update>
在线上的时候一直报这样的错误:
然后上网查询说是配置mysql的时候没有开启批量插入,就查询了项目的是否配置了allowMultiQueries=true,发现本地和线上都配置了该语句,问题没出在这,
那问题出在哪呢,后来发现是由于线上将&变成了&造成的.前后对比如下:
修改前:
jdbc.url=jdbc:mysql://XXX/abc?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true修改后:
这样一个bug整整让我改了2天,记录下,希望有同样问题的同学能顺利解决
<!--批量更新报表 -->
<update id="updateIssueByBatch" parameterType="java.util.List">
<foreach collection="issueList" item="item" index="index" separator=";">
update sys_issue
<set>
<if test="item.first != null and item.first != ''">first_class = #{item.first}, </if>
<if test="item.second != null and item.second != ''">second_class = #{item.second}, </if>
updated_time = now()
</set>
where id = #{item.Id}
</foreach>
</update>
在线上的时候一直报这样的错误:
The error occurred while setting parameters刚开始一直以为是由于线上的数据和本地的数据不一致造成的,把线上的数据拿过来测试了很多会还是报同样的错,
然后上网查询说是配置mysql的时候没有开启批量插入,就查询了项目的是否配置了allowMultiQueries=true,发现本地和线上都配置了该语句,问题没出在这,
那问题出在哪呢,后来发现是由于线上将&变成了&造成的.前后对比如下:
修改前:
jdbc.url=jdbc:mysql://XXX/abc?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true修改后:
jdbc.url=jdbc:mysql://XXX/abc?useUnicode=true&zeroDateTimeBehavior=convertToNull&allowMultiQueries=true
这样一个bug整整让我改了2天,记录下,希望有同样问题的同学能顺利解决
相关文章推荐
- svn Update取消或关闭再次更新失败解决办法
- android studio check for update 更新失败
- ubuntu apt-get update 更新失败
- apt-update 更新失败 (无法连接到ubuntu服务器)
- mysql-workbench工具update(更新)失败的解决办法
- 删除Maven更新失败后遗留的.lastUpdate文件问题
- mysql-workbench工具update(更新)失败的解决办法
- hibernate 级联删除报更新失败的问题(org.hibernate.exception.GenericJDBCException: Could not execute JDBC batch update)
- mysql-workbench工具update(更新)失败的解决办法
- mybatis批量更新update-设置多个字段值
- a1c9 Linux 遇到apt update中遇到更新失败的问题尝试方法
- 通过update-mapping更新child的field失败——NullPointerException
- 关于window update 检查更新总是失败的解决方案
- Windows 7 Ultimate x64 (7600) update failed with error code 8024402F (更新失败)
- Win7 Update更新安装失败或者无法自动更新安装
- Win8.1 Update更新失败错误代码为80073712
- 关于windows7的更新update失败,windows media play安装失败的 ...
- 2个命令解决windows8.1 update更新失败
- 第五章 mybatis批量更新update
- mybatis批量更新update-设置多个字段值