StringIndexOutOfBoundsException: String index out of range: 458

报错信息:

java 复制代码
org.springframework.dao.TransientDataAccessResourceException:
### Error updating database. Cause: java.sql.SQLException: java.lang.StringIndexOutOfBoundsException: String index out of range: 458
...
...
...

问题原因:

java 复制代码
 <insert id="batchInsert" parameterType="java.util.List" >
    insert into table_name (省略...)
    values
    <foreach collection="list" index="index" item="item" open="" separator="," close="">
      (
        省略...
      )
    </foreach>
  </insert>

<update id="batchUpdate" parameterType="xxx" >
   <foreach collection="list" index="index" item="item" open="" separator=";" close="">
        (
             update table_name set xxxx = #{xx,jdbcType=INTEGER}... where ...
                      省略...
        )
   </foreach>
   
  </update>

调用批量插入或更新操作时,如果list为null或者size()==0,导致此错误

解决方案:

调用批量操作前,判断list是否为null,或者size()==0,如果是则不调用批量操作。

相关推荐
2301_7903009621 小时前
C++中的命令模式
开发语言·c++·算法
2301_8223769421 小时前
C++中的解释器模式
开发语言·c++·算法
czlczl2002092521 小时前
Spring Boot :如何高性能地在 Filter 中获取响应体(Response Body)
java·spring boot·后端
爱学习的阿磊21 小时前
C++代码冗余消除
开发语言·c++·算法
sg_knight21 小时前
抽象工厂模式(Abstract Factory)
java·python·设计模式·抽象工厂模式·开发
春日见21 小时前
win11 分屏设置
java·开发语言·驱动开发·docker·单例模式·计算机外设
2301_780029041 天前
支付宝sdk导入错误
java·开发语言·maven
码界奇点1 天前
基于Spring Boot和Vue3的无头内容管理系统设计与实现
java·spring boot·后端·vue·毕业设计·源代码管理
九皇叔叔1 天前
【03】微服务系列 之Nacos 注册中心(服务注册)
java·微服务·nacos·架构·注册中心·服务注册
木辰風1 天前
PLSQL自定义自动替换(AutoReplace)
java·数据库·sql