mybatis批量更新(update foreach)失败

来源:互联网 发布:js 仿京东楼层特效 编辑:程序博客网 时间:2024/05/24 22:45

最近做项目需要一个很奇葩的现象,项目是spring+springMvc+mybatis ,在本地进行批量更新时是成功的,但上到线上环境就一直报错,代码如下:

 <!--批量更新报表  -->   <update id="updateIssueReportByBatch" parameterType="java.util.List">        <foreach collection="issueReportList" item="item" index="index"  separator=";">            update sys_issue_report            <set>                <if test="item.firstClass != null and item.firstClass != ''"><![CDATA[first_class = #{item.firstClass},]]> </if>                <if test="item.secondClass != null and item.secondClass != ''"><![CDATA[second_class = #{item.secondClass},]]> </if>                updated_time = now()            </set>            where issue_id = #{item.issueId} and status = 1          </foreach>  </update>

在线上的时候一直报这样的错误: 
The error occurred while setting parameters  
刚开始一直以为是由于线上的数据和本地的数据不一致造成的,把线上的数据拿过来测试了很多会还是报同样的错,

然后上网查询说是配置mysql的时候没有开启批量插入,就查询了项目的是否配置了allowMultiQueries=true,发现本地和线上都配置了该语句,问题没出在这,

那问题出在哪呢,后来发现是由于线上将&变成了&amp;造成的.前后对比如下:

修改前:

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天,记录下,希望有同样问题的同学能顺利解决