系统城装机大师 - 固镇县祥瑞电脑科技销售部宣传站!

当前位置:首页 > 系统教程 > 其它教程 > 详细页面

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

时间:2020-11-10来源:www.pcxitongcheng.com作者:电脑系统城

批量修改代码如下

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<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中代码:

?
1
2
3
4
5
6
7
8
9
10
11
<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语句

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。

分享到:

相关信息

  • ThinkPad蓝牙鼠标如何配对

    ThinkPad蓝牙鼠标如何配对解答步骤41U5008鼠标驱动官网地址: https://support.lenovo.com/en_US/downloads/detail.page?&LegacyDocID=MIGR-67201 第一种方式是比较传统的:使...

    2024-04-11

  • USB接口无法识别设备的解决方法

    故障现象: USB设备U盘、移动硬盘等插入后提示无法识别的设备,确认设备本身正常,设备可加电,或插入设备后加电但无任何反应,无法使用。新型号机器多表现为黄色USB接口存在此问题,...

    2024-04-11

系统教程栏目

栏目热门教程

人气教程排行

站长推荐

热门系统下载