问题架构
后端springboot+mybatis, 前端html+绿叶子
问题描述
首先,数据库的parentId字段为varchar类型
数据库数据也正常
但是,进入页面报错

报错内容主要有两个
org.springframework.dao.DataIntegrityViolationException: Error attempting to get column 'ParentID' from result set. Cause: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '1.6728787980030976E18' in column '2' is outside valid range for the datatype INTEGER.
; '1.6728787980030976E18' in column '2' is outside valid range for the datatype INTEGER.; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '1.6728787980030976E18' in column '2' is outside valid range for the datatype INTEGER.
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLDataException: '1.6728787980030976E18' in column '2' is outside valid range for the datatype INTEGER.
这里就很奇怪,后台的Entity也是String类型,不存在Integer
尝试解决
尝试了以下方式,没有任何作用
- 删除表重建
- 重新生成代码,替换代码
- mvn clean,然后重新编译
解决办法
我看到column '2' 猜测是可能是sql解析时,数据库字段串行?
将下面两个字段改为String,解决问题
总结
很奇怪的bug。写了三年代码了,头一次遇到这种问题。目前对出现的原理还是一头雾水。