当前使用版本(必填,否则不予处理)

3.5.0, 3.5.1, 3.5.2三个版本都试过

该问题是如何引起的?(确定最新版也有问题再提!!!)

实体类使用了枚举,添加数据可以正常转换,查询的时候转换失败。

重现步骤(如果有就写完整)

枚举对象: public enum UserType implements IEnum {

PHONE_USER(1),

EMAIL_USER(2),
;
public final Integer type;

UserType(Integer type) {
    this.type = type;
}

@Override
public Integer getValue() {
    return this.type;
}

} 实体对象: public class UserConnection extends BaseInfo {

private UserType userType;

}

save(bean) 保存正常,list()查询错误。 经过调试问题出在 MybatisEnumTypeHandler 类的以下方法中 @Override public E getNullableResult(ResultSet rs, String columnName) throws SQLException { //这里的getObject报的错误。如果是getObject(columnName)则不会报错,且返回的数据与this.propertyType类型一致。 Object value = rs.getObject(columnName, this.propertyType); if (null == value && rs.wasNull()) { return null; } return this.valueOf(value); }

以下为调试截图 MyBatis-Plus 枚举转换错误

报错信息

Error attempting to get column 'type' from result set. Cause: java.sql.SQLFeatureNotSupportedException

Comment From: 1146604040

MyBatis-Plus 枚举转换错误 经过调试:通过getObject(columnName)获取到的数据类型与this.propertyType一致,但是无法通过getObject(column,type)获取

Comment From: miemieYaho

你的数据库驱动不支持jdbc那个method

Comment From: xsg22

MyBatis-Plus 枚举转换错误 经过调试:通过getObject(columnName)获取到的数据类型与this.propertyType一致,但是无法通过getObject(column,type)获取

我也碰到这个问题,原因是我使用的druid版本过低(1.1.20),rs.getObject(columnName, this.propertyType)会调用druid的getObject(String columnLabel, Class type)方法,druid直接抛异常。把druid升级到1.2.9就正常了。

public <T> T getObject(String columnLabel, Class<T> type) throws SQLException {
    throw new SQLFeatureNotSupportedException();
}