Mybatis批量修改时出现报错问题解决方案
作者:cqy19951026 时间:2022-05-15 19:07:40
批量修改代码如下
<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
标签:Mybatis,批量,修改,报错
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Java swing实现酒店管理系统
2021-08-08 02:24:12
java如何使用自己的maven本地仓库详解
2022-08-01 12:13:44
详解Spring Boot最核心的27个注解,你了解多少?
2023-11-20 06:23:35
Java深入讲解static操作符
2023-11-27 00:59:16
![](https://img.aspxhome.com/file/2023/5/60105_0s.png)
Android中通过样式来去除app的头及界面全屏(备忘)的实现方法
2023-07-30 00:03:23
Toolbar制作菜单条过程详解
2022-11-29 04:13:59
Java基于IO流读取文件的方法
2023-08-11 16:23:57
Java中常见的对象转换工具
2023-12-14 19:23:16
![](https://img.aspxhome.com/file/2023/6/71886_0s.webp)
详解Java进阶知识注解
2023-08-12 13:11:37
![](https://img.aspxhome.com/file/2023/5/65775_0s.png)
java服务器的简单实现过程记录
2023-01-18 06:44:34
java连接SQL Server数据库的方法
2022-10-14 04:16:56
![](https://img.aspxhome.com/file/2023/3/63093_0s.png)
浅谈Java序列化和hessian序列化的差异
2022-11-17 07:46:13
mybatis中resultMap 标签的使用教程
2022-01-15 11:19:42
![](https://img.aspxhome.com/file/2023/3/68533_0s.png)
Mybatis中如何进行批量更新(updateBatch)
2022-10-11 13:42:00
初识MyBatis及基本配置和执行
2021-11-12 05:53:40
![](https://img.aspxhome.com/file/2023/7/75487_0s.jpg)
OpenCV实现人脸识别简单程序
2023-07-07 00:31:12
Android控件之SlidingDrawer(滑动式抽屉)详解与实例分享
2023-07-27 09:26:18
![](https://img.aspxhome.com/file/2023/2/85982_0s.jpg)
深入谈谈C#9新特性的实际运用
2021-05-26 16:08:23
Java SpringBoot整合shiro-spring-boot-starterqi项目报错解决
2022-11-07 03:27:02
![](https://img.aspxhome.com/file/2023/0/69650_0s.png)
Java基础之多线程
2022-11-30 11:01:43