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

相关推荐
爱喝一杯白开水3 分钟前
SpringMVC从入门到上手-全面讲解SpringMVC的使用.
java·spring·springmvc
王景程13 分钟前
如何测试短信接口
java·服务器·前端
安冬的码畜日常36 分钟前
【AI 加持下的 Python 编程实战 2_10】DIY 拓展:从扫雷小游戏开发再探问题分解与 AI 代码调试能力(中)
开发语言·前端·人工智能·ai·扫雷游戏·ai辅助编程·辅助编程
朝阳5811 小时前
Rust项目GPG签名配置指南
开发语言·后端·rust
朝阳5811 小时前
Rust实现高性能目录扫描工具ll的技术解析
开发语言·后端·rust
程高兴1 小时前
基于Matlab的车牌识别系统
开发语言·matlab
zhang23839061541 小时前
IDEA add gitlab account 提示
java·gitlab·intellij-idea·idea
牛马baby1 小时前
Java高频面试之并发编程-07
java·开发语言·面试
CodeWithMe2 小时前
【C++】STL之deque
开发语言·c++
卓怡学长2 小时前
w304基于HTML5的民谣网站的设计与实现
java·前端·数据库·spring boot·spring·html5