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

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