‘XXXXX‘ is outside of valid range for type 错误分析

时间:2025-02-09 17:49:37

使用mybatis自动映射数据库和实体类时,报出如下错误

: Error attempting to get column 'tel' from result set.  Cause: : Value '4006184000' is outside of valid range for type 
; Value 'xxxxx' is outside of valid range for type ; nested exception is : Value '4006184000' is outside of valid range for type 

追查原因,发现有两个原因会造成这样的错误

  1. 数据库的字段属性与实体类的字段属性不符,造成类型超出范围,实际该字段在代码中对应Integer类型,数据库中对应varchar类型。把实体类属性改成String,就可以了。

  1. 实体类中只有有参构造,没有无参构造,导致Mybatis使用XML查询时结果(集)无法映射为类实例(列表)