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 a3bc2c4..ba57d14 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 @@ -1,7 +1,7 @@ package com.flyfish.framework.beans.meta; -import com.flyfish.framework.annotations.*; import com.flyfish.framework.annotations.Properties; +import com.flyfish.framework.annotations.*; import com.flyfish.framework.domain.base.Qo; import com.flyfish.framework.domain.base.Vo; import com.flyfish.framework.utils.DataUtils; @@ -13,6 +13,7 @@ import org.apache.commons.lang3.ClassUtils; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.TypeUtils; import org.springframework.beans.BeanUtils; +import org.springframework.core.annotation.AnnotatedElementUtils; import org.springframework.core.annotation.AnnotationUtils; import org.springframework.data.mongodb.core.mapping.Document; @@ -106,11 +107,11 @@ public class BeanProperty { property.prop("code", name); } else if (field.isAnnotationPresent(DBRefValue.class)) { // 添加了数据库引用注解,自动注入类型给前端使用 - property.setType(BeanPropertyType.DB_REF); DBRefValue dbRefValue = field.getAnnotation(DBRefValue.class); - Document document = AnnotationUtils.findAnnotation(dbRefValue.value(), Document.class); - if (null != document) { - property.prop("uri", document.collection()); + Optional optional = processDbRef(dbRefValue.value()); + if (optional.isPresent()) { + property.setType(BeanPropertyType.DB_REF); + property.prop("uri", optional.get()); } else { property.setType(BeanPropertyType.STRING); } @@ -131,9 +132,9 @@ public class BeanProperty { break; case DB_REF: // 当存在db-ref时,解析为动态数据源 - Document document = AnnotationUtils.findAnnotation(clazz, Document.class); - if (null != document) { - property.prop("uri", document.collection()); + Optional optional = processDbRef(clazz); + if (optional.isPresent()) { + property.prop("uri", optional.get()); } else { property.setType(BeanPropertyType.STRING); } @@ -162,6 +163,17 @@ public class BeanProperty { return ListUtils.union(parseExtras(clazz), properties); } + /** + * 解析db引用的参数 + * + * @param clazz 类 + * @return 结果 + */ + private static Optional processDbRef(Class clazz) { + return Optional.ofNullable(AnnotatedElementUtils.findMergedAnnotation(clazz, Document.class)) + .map(Document::value); + } + /** * 解析额外的注解 *