您的位置:首页 > 产品设计 > UI/UE

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>
在线上的时候一直报这样的错误: 
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天,记录下,希望有同样问题的同学能顺利解决
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息