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)));