java.lang.NumberFormatException: For input string: "" 或 "[]" 解决方案
异常原因
引起异常的主要原因如下:
- 传参字段和映射字段不一致
- 传参类型和映射类型不一致
- 时间类型转换时间戳长度不一致
- 参数长度和数据库不一致
- 没有判空!!!
List<?> 判空问题导致
这里使用参数 relationIdList 作为示例,参数类型为 List
<if test="relationIdList != null and relationIdList.size() > 0">
and relation_id in
<foreach collection="relationIdList" item="item" open="(" close=")" separator=",">
#{item}
</foreach>
</if>
注意使用 List<?> 作为Mybatis的查询条件时,不光需要判空,还需要判断一下长度。java.lang.NumberFormatException: For input string: “[]”
这个异常就是因为没有判断List数组的长度,结果给SQL传入一个空数组,报错。