我的环境
Springboot 2.13 + Mybatis Plus 3.1 + Oracle 11g(驱动版本oracle6)
1、我尝试用 Mybatis Plus 3.1 以上版本 如 3.2、3.3 时,oracle6 驱动无法适配
2、枚举类处理器
a) org.apache.ibatis.type.EnumOrdinalTypeHandler 使用时不会报错,但是通过索引处理的值不对,返回的是枚举类下标的值
示列:
数据库:
-
枚举类:
-
返回结果:
-
发现返回的结果是枚举类的下标对应的值,所以下面需要重写,如果使用的是mybatis plus 3.3直接在枚举类的code使用@EnumValue注解
b) org.apache.ibatis.type.EnumTypeHandler 使用时直接报错
重写处理器
/**
* 定义枚举类接口, 后面需要实现
**/
public interface EnumCodeService {
int code();
}
- [b]
枚举类帮组类,通过code返回对应的数据:
// 帮组类
public class EnumCodeUtil {
public static <E extends Enum<E> & EnumCodeService> E manageCode(Class<E> enumClass, int code) {
E[] enumConstants = enumClass.getEnumConstants();
for (E e : enumConstants)