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

相关推荐
FYKJ_201014 分钟前
django乌鲁木齐市二手房房价可视化平台84751-计算机毕业设计、课程设计
java·vue.js·spring boot·后端·信息可视化·django·课程设计
Shaoshing15 分钟前
LeetCode100 560.和为k的子数组
java·数据结构·算法
codezzzsleep1 小时前
让个人智能体安全地接触外部资料
java·前端·安全
li星野2 小时前
Qt 单例配置管理器学习记录:JsonConfigManager 的设计原理与使用示例
开发语言·qt·学习
FYKJ_20102 小时前
springboot高校实验室综合管理系统86531-计算机毕业设计、课程设计
java·vue.js·spring boot·后端·python·spring·课程设计
钱栈up3 小时前
AND t.unit_code = 'SM1':一行写死的 SQL 让配料计划页永远拿不到化验值
java·sql·微服务
金銀銅鐵8 小时前
类实例里还有什么——putfield、getfield 与对象传递
java·jvm·后端
默 语9 小时前
HarmonyOS7 事件分发控制(二):onTouchIntercept 镂空玻璃卡——圆内自己接,圆外放行
android·java·开发语言
Amumu1213810 小时前
TypeScript学习: 基础知识(二)
开发语言·typescript·ecmascript
sharemylove11 小时前
Java 异常与常用类 学习笔记
java·开发语言·经验分享·笔记·学习