解决方法
删除resultMap中手动指定的typeHandler
不可行
<result column="type" property="type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
可行
<result column="type" property="type" />
背景
mybatis-plus版本:3.4.3
spring-cloud版本:Hoxton.SR8
业务背景
前端需要很多下拉列表,这些下拉列表的值都是后端接口返回的;数据格式为:
{
"EMPLOYEE": [
{
"label": "张三",
"value": "code1"
},
{
"label": "李四",
"value": "code2"
}
],
"GROUP_CHAT": [
{
"label": "群聊1",
"value": "group1"
}
]
}
其中EMPLOYEE
,GROUP_CHAT
都是后端定义的枚举
public enum SimpleEnum{
EMPLOYEE,
GROUP_CHAT
}
数据库ResultMap对应的对象
public class SelectBO{
private SimpleEnum type;
private String label;
private String value;
// ..get set method..
}
数据库ResultMap
<resultMap id="selectListResult" type="SelectBO">
<result column="type" property="type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
<result column="id" property="value"/>
<result column="name" property="label"/>
</resultMap>
出现的问题
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.executor.result.ResultMapException:
Error attempting to get column 'select_type' from result set. Cause: java.lang.IllegalArgumentException: No enum constant xxxs.MaterialTypeEnum.EMPLOYEE
这个错误只在线上出现(偶尔),本地启项目出现不了这个问题QWQ。
出现这个问题的根本原因在于,在项目启动阶段mybatis在初始化的过程中将枚举映射错了,我也是在把服务器代码弄下来,远程调试本地代码发现的
后来我将服务器代码里面的相应ResultMap对应xml的typeHandler去掉再启动项目就能解决问题
不可行
<result column="type" property="type" typeHandler="org.apache.ibatis.type.EnumTypeHandler"/>
可行
<result column="type" property="type" />