From c1cd6dcecd69901b3bef2f9b80a3fd0c13cfbba8 Mon Sep 17 00:00:00 2001 From: CShisan <510696435@qq.com> Date: Fri, 7 Nov 2025 18:00:49 +0800 Subject: [PATCH] =?UTF-8?q?fix=20=E4=BF=AE=E5=A4=8D@EnumValue=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E5=9C=A8=E6=8E=A5=E5=8F=A3=E6=96=B9=E6=B3=95=E4=B8=94?= =?UTF-8?q?=E8=BF=94=E5=9B=9E=E7=B1=BB=E5=9E=8B=E4=B8=BA=E6=B3=9B=E5=9E=8B?= =?UTF-8?q?=E6=97=B6=E5=A4=B1=E6=95=88=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mybatisflex/core/util/EnumWrapper.java | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) 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 2afb354d..765ab640 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 @@ -77,13 +77,22 @@ public class EnumWrapper> { if (!(methodName.startsWith("get") && methodName.length() > 3)) { throw new IllegalStateException("Can not find get method \"" + methodName + "()\" in enum: " + enumClass.getName()); } + + String enumValueFieldName; + if (methodName.startsWith("get")) { + enumValueFieldName = StringUtil.firstCharToLowerCase(enumValueMethod.getName().substring(3)); + } else { + enumValueFieldName = enumValueMethod.getName().toLowerCase(); + } + enumValueField = ClassUtil.getFirstField(enumClass, field -> enumValueFieldName.equals(field.getName())); + if (enumValueField != null) { + propertyType = ClassUtil.getWrapType(enumValueField.getType()); + } else { + throw new IllegalStateException("Can not find field \"" + enumValueFieldName + "()\" in enum: " + enumClass.getName()); + } + this.getterMethod = enumValueMethod; this.hasEnumValueAnnotation = true; - Class returnType = enumValueMethod.getReturnType(); - if (returnType.isPrimitive()) { - returnType = ConvertUtil.primitiveToBoxed(returnType); - } - this.propertyType = returnType; } } }