From 3566c9facff50dd1bb305086100e7684ecd493e8 Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Wed, 7 Apr 2021 17:08:55 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E7=BB=84=E4=BB=B6=E9=93=BE=E6=8E=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/utils/ReflectionUtils.java | 22 +++++++++++++++++++ .../framework/beans/meta/BeanProperty.java | 8 +++---- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/flyfish-common/src/main/java/com/flyfish/framework/utils/ReflectionUtils.java b/flyfish-common/src/main/java/com/flyfish/framework/utils/ReflectionUtils.java index 3872d26..1a08cb8 100644 --- a/flyfish-common/src/main/java/com/flyfish/framework/utils/ReflectionUtils.java +++ b/flyfish-common/src/main/java/com/flyfish/framework/utils/ReflectionUtils.java @@ -340,14 +340,36 @@ public class ReflectionUtils { /** * 获取范型,默认取得第一个 + * * @param clazz 类 * @return 结果 */ public static Optional> getGenericType(Class clazz) { ParameterizedType type = CastUtils.cast(clazz.getGenericSuperclass()); + return getGenericType(type); + } + + /** + * 通过类型获取泛型 + * + * @param type 类型 + * @return 结果 + */ + public static Optional> getGenericType(ParameterizedType type) { return Optional.ofNullable(type.getActualTypeArguments()).filter(ArrayUtils::isNotEmpty) .map(array -> array[0]) .filter(beanType -> beanType instanceof Class) .map(beanType -> (Class) beanType); } + + /** + * 获取字段域的泛型 + * + * @param field 字段 + * @return 结果 + */ + public static Optional> getGenericType(Field field) { + ParameterizedType type = CastUtils.cast(field.getGenericType()); + return getGenericType(type); + } } diff --git a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java index 1880c88..7573f04 100644 --- a/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java +++ b/flyfish-web/src/main/java/com/flyfish/framework/beans/meta/BeanProperty.java @@ -122,11 +122,11 @@ public class BeanProperty { } break; case LIST: - // 是附件,展现附件列表 - ReflectionUtils.getGenericType(descriptor.getPropertyType()) - .filter(property::isAttachment) - .ifPresent(item -> property.prop("attachment", true)); if (null != field) { + // 是附件,展现附件列表 + ReflectionUtils.getGenericType(field) + .filter(property::isAttachment) + .ifPresent(item -> property.prop("attachment", true)); if (field.isAnnotationPresent(SubBean.class)) { // 尝试获取泛型参数,存在时,赋值子表单 parseSubClass(field).ifPresent(subClazz -> property.setChildren(from(subClazz)));