StringIndexOutOfBoundsException: String index out of range: 458

报错信息:

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

问题原因:

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

猜你喜欢

转载自blog.csdn.net/bingxuesiyang/article/details/132411690
今日推荐