fix: 回滚到仅支持get方法级别EnumValue注解

This commit is contained in:
hy 2024-01-18 23:00:20 +08:00
parent 984ed7eb60
commit 64a625d098
3 changed files with 14 additions and 26 deletions

View File

@ -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、当配置了 @EnumValueQueryWrapper 构建时,传入枚举,自动使用该值进行 SQL 参数拼接。例如:

View File

@ -41,12 +41,7 @@ public class CompositeEnumTypeHandler<E extends Enum<E>> implements TypeHandler<
if (enumDbValueFields.isEmpty()) {
List<Method> enumDbValueMethods = ClassUtil.getAllMethods(enumClass, m -> m.getAnnotation(EnumValue.class) != null);
if (enumDbValueMethods.isEmpty()) {
List<Method> 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) {

View File

@ -73,15 +73,6 @@ public class EnumWrapper<E extends Enum<E>> {
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;
}