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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章