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,如果是则不调用批量操作。

相关推荐
apcipot_rain1 小时前
C++转Java日记(06)
java·开发语言
金銀銅鐵6 小时前
带您看懂字节码指令(一):一帧里有什么
java·后端·ai编程
nice_lcj5208 小时前
【从零理解 Spring AI · 14】RAG 的四个环节:加载、切分、向量化、检索
java·spring boot·embedding·向量数据库·rag·spring ai·ai应用开发
SomeOtherTime8 小时前
Rust所有权(AI回答)
开发语言·后端·rust
Easyhood8 小时前
Android 开发入门实践(十四):Compose 副作用入门与四个常用 API
android·开发语言·kotlin·android jetpack·compose
白杨尚青9 小时前
C++进阶篇(六):map 和 set 的模拟实现——用红黑树封装 mymap/myset(迭代器 + operator[])
开发语言·c++·迭代器·stl·set·map·红黑树
学长毕设9 小时前
基于springboot科创竞赛信息平台-附源码
java·spring boot·后端
聪明的笨猪猪10 小时前
Java 工程案例:AI 生成 @Async 异步线程池踩坑
java·经验分享·面试·ai编程
学长毕设10 小时前
基于SpringBoot公务员考试交流平台-附源码
java·spring boot·后端
SL_staff12 小时前
私有化低代码:面向强监管行业的可控数字化实践
java·低代码