From 64a625d0985cad9ca1ddc874b1f126abf9c2fc40 Mon Sep 17 00:00:00 2001 From: hy <1514244102@qq.com> Date: Thu, 18 Jan 2024 23:00:20 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=9E=E6=BB=9A=E5=88=B0=E4=BB=85?= =?UTF-8?q?=E6=94=AF=E6=8C=81get=E6=96=B9=E6=B3=95=E7=BA=A7=E5=88=ABEnumVa?= =?UTF-8?q?lue=E6=B3=A8=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/zh/core/enum-property.md | 24 ++++++++++--------- .../handler/CompositeEnumTypeHandler.java | 7 +----- .../mybatisflex/core/util/EnumWrapper.java | 9 ------- 3 files changed, 14 insertions(+), 26 deletions(-) diff --git a/docs/zh/core/enum-property.md b/docs/zh/core/enum-property.md index c832dd67..bbc8a5d6 100644 --- a/docs/zh/core/enum-property.md +++ b/docs/zh/core/enum-property.md @@ -41,18 +41,11 @@ public enum TypeEnum { //getter } ``` -```java -public interface BaseEnum { - @EnumValue // 当注解写在枚举基类接口里 - Integer getCode(); - String getDesc(); -} -``` ```java -@Getter + @AllArgsConstructor -public enum EnableEnum implements BaseEnum { +public enum EnableEnum { /** * 启用 */ @@ -64,6 +57,15 @@ public enum EnableEnum implements BaseEnum { ; private final int code; private final String desc; + + @EnumValue + public int getCode() { + return code; + } + + public String getDesc() { + return desc; + } } ``` @@ -74,8 +76,8 @@ public enum EnableEnum implements BaseEnum { **注意事项** - 1、@EnumValue 注解标识的属性,要求必须是 public 修饰,或者有 get 方法。 -- 2、@EnumValue 注解标识支持在 get 方法使用注解,也支持在基类接口上的get方法上使用注解。 -- 3、枚举注解优先级。 优先取字段上的注解。如果字段没有注解,则会找方法上的注解,如果枚举类当前方法没有注解,则会去找父类或者父接口的方法寻找存在注解的方法。 +- 2、@EnumValue 注解标识支持在 get 方法使用注解。 +- 3、枚举注解优先级。 优先取字段上的注解。如果字段没有注解,则会找方法上的注解,如果枚举类当前方法没有注解,则会去找父类的方法寻找存在注解的方法。 - 4、当配置了 @EnumValue 时,QueryWrapper 构建时,传入枚举,自动使用该值进行 SQL 参数拼接。例如: diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java index 052f554a..649ebb8b 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/handler/CompositeEnumTypeHandler.java @@ -41,12 +41,7 @@ public class CompositeEnumTypeHandler> implements TypeHandler< if (enumDbValueFields.isEmpty()) { List enumDbValueMethods = ClassUtil.getAllMethods(enumClass, m -> m.getAnnotation(EnumValue.class) != null); if (enumDbValueMethods.isEmpty()) { - List enumDbInterfaceMethodList = Arrays.stream(enumClass.getInterfaces()) - .flatMap(inter -> ClassUtil.getAllMethods(inter, m -> m.getAnnotation(EnumValue.class) != null).stream()) - .collect(Collectors.toList()); - if (enumDbInterfaceMethodList.isEmpty()) { - isNotFound = true; - } + isNotFound = true; } } if (isNotFound) { diff --git a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java index 2e60dfd9..e2973761 100644 --- a/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java +++ b/mybatis-flex-core/src/main/java/com/mybatisflex/core/util/EnumWrapper.java @@ -73,15 +73,6 @@ public class EnumWrapper> { if (!hasEnumValueAnnotation) { Method enumValueMethod = ClassUtil.getFirstMethod(enumClass, method -> method.getAnnotation(EnumValue.class) != null); - if (enumValueMethod == null) { - Class[] interfaces = enumClass.getInterfaces(); - for (Class anInterface : interfaces) { - enumValueMethod = ClassUtil.getFirstMethod(anInterface, method -> method.getAnnotation(EnumValue.class) != null); - if (enumValueMethod != null) { - break; - } - } - } if (enumValueMethod != null) { this.getterMethod = enumValueMethod; }