mybatis批量更新 一条成功,多条失败

<!-- 批量更新 -->

        <updateid="updatePlanList" parameterType="java.util.List">

               <foreachcollection="list" item="item" index="index"open="" close="" separator=";">

                       updateplan

                               <set>

                                      <iftest="item.planName != null">

                                       planName = #{item.planName},

                                  </if>

                                  <if test="item.planContent!=null">

                                              planContent= #{item.planContent}

                                  </if>

                               </set>

                               whereid=#{item.id}

               </foreach>

        </update>

 

一直报错,错误如下

严重: Servlet.service() forservlet [mvc-dispatcher] in context with path [/smallProject] threw exception[Request processing failed; nested exception isorg.springframework.jdbc.BadSqlGrammarException:

### Error updatingdatabase.  Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException:You have an error in your SQL syntax; check the manual that corresponds to yourMySQL server version for the right syntax to use near 'update plan

                                SET planName = '2222',

                                  

                                  

   ' at line 8

### The error mayinvolve com.xiaorui.mapper.PlanMapper.updatePlanList-Inline

### The erroroccurred while setting parameters

网上搜索一番,发现这需要修改数据源连接配置

比如:jdbc:mysql://192.168.1.236:3306/test?useUnicode=true&amp;characterEncoding=UTF-8&allowMultiQueries=true

但是我数据源配置在xml中,报The reference to entity "allowMultiQueries" must end withthe ';' delimiter.错误

<propertyname="url"value="jdbc:mysql://localhost:3306/xiaorui?characterEncoding=UTF-8&allowMultiQueries=true"/>

        <property name="username"value="root" />

        <property name="password"value="123456" />

        <propertyname="driverClassName" value="com.mysql.jdbc.Driver" />

原来&等特殊符号在xml中需要转义

&lt;<小于号
&gt;>大于号
&amp;&
&apos;'单引号
&quot;"双引号

 

修改如下

<propertyname="url"value="jdbc:mysql://localhost:3306/xiaorui?characterEncoding=UTF-8&amp;allowMultiQueries=true" />
        <property name="username"value="root" />
        <property name="password"value="123456" />
        <property name="driverClassName"value="com.mysql.jdbc.Driver" />

但是这样批量更新返回的影响行数就为1

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值