软件编程
位置:首页>> 软件编程>> java编程>> Mybatis批量修改时出现报错问题解决方案

Mybatis批量修改时出现报错问题解决方案

作者:cqy19951026  发布时间:2022-05-15 19:07:40 

标签:Mybatis,批量,修改,报错

批量修改代码如下


<update id="UPDATE_HOTEL_REAL_TIME_PRICE" parameterType="java.util.List">
   <foreach collection="list" item="item" index="index" separator=";">
     UPDATE VST_HOTEL_REAL_TIME_PRICE
     <set>
       <if test="item.realTimePrice1 != null">
         REAL_TIME_PRICE1 = #{item.realTimePrice1},
       </if>
       <if test="item.realTimePrice2 != null">
         REAL_TIME_PRICE2 = #{item.realTimePrice2},
       </if>
       <if test="item.realTimeRemain1 != null">
         REAL_TIME_REMAIN1 = #{item.realTimeRemain1},
       </if>
       <if test="item.realTimeRemain2 != null">
         REAL_TIME_REMAIN2 = #{item.realTimeRemain2},
       </if>
       UPDATE_TIME = NOW()
     </set>
     WHERE PRODUCT_ID = ${item.productId}
    </foreach>
  </update>

今天在使用mybatis批量修改时报错,错误为sql语句错误:

开始检查xml中代码:


<update id="updateTypeList" parameterType="list">
   <foreach collection="list" item="type" index="index" separator=";">
     UPDATE t_type
     <set>
       <if test="type.name != null">
         t_name = #{type.name}
       </if>
     </set>
     where t_id = #{type.id}
   </foreach>
 </update>

感觉并没有错误,把错误语句复制到Navicat上能正常运行,于是网上查找了一下需要在url语句中添加allowMultiQueries=true,添加后成功运行。

Mysql中allowMultiQueries=true作用:

1.可以在sql语句后携带分号,实现多语句执行。

2.可以执行批处理,同时发出多个SQL语句

来源:https://www.cnblogs.com/cqy1026/p/13904820.html

0
投稿

猜你喜欢

手机版 软件编程 asp之家 www.aspxhome.com