diff --git a/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java b/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java index 5500416..ffb6d46 100644 --- a/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java +++ b/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/BeanPropertyAnnotations.java @@ -74,6 +74,18 @@ public interface BeanPropertyAnnotations { BeanPropertyAnnotationBatchChain> as( Class annotationType, Class listType); + /** + * 判断某个注解是否存在,存在则交给consumer进行处理,取得所有注解并自动判断复数形式 + * + * @param annotationType 注解类型 + * @param listType 列表类型 + * @param 泛型 + * @param 列表泛型 + * @return 结果 + */ + BeanPropertyAnnotationBatchChain> as( + String annotationType, String listType); + /** * 设置上一步结果 * diff --git a/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java b/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java index f1ede48..90f4c4e 100644 --- a/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java +++ b/flyfish-bean/src/main/java/dev/flyfish/framework/beans/meta/parser/SimpleBeanPropertyAnnotations.java @@ -13,6 +13,7 @@ import org.springframework.util.CollectionUtils; import java.lang.annotation.Annotation; import java.lang.reflect.AnnotatedElement; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.stream.Collectors; @@ -127,6 +128,39 @@ public class SimpleBeanPropertyAnnotations implements BeanPropertyAnnotations { return batchEmpty(); } + /** + * 判断某个注解是否存在,存在则交给consumer进行处理,取得所有注解并自动判断复数形式 + * + * @param annotationType 注解类型 + * @param listType 列表类型 + * @return 结果 + */ + @Override + @SuppressWarnings("unchecked") + public BeanPropertyAnnotationBatchChain> as(String annotationType, String listType) { + if (null != field && !this.last) { + MergedAnnotation annotation = this.annotations.get(listType); + // 存在注解容器,读取之 + if (annotation.isPresent()) { + List> picked = annotation.getValue("value") + .map(value -> Arrays.asList((MergedAnnotation[]) value)) + .orElse(Collections.emptyList()); + if (!CollectionUtils.isEmpty(picked)) { + return new SimpleAnnotationBatchChain<>(this.last(true), picked); + } + } + // 不存在或为空,查找直接注解的(大多数是一个) + List> values = this.annotations.stream(annotationType) + .filter(MergedAnnotation::isPresent) + .collect(Collectors.toList()); + if (!CollectionUtils.isEmpty(values)) { + return new SimpleAnnotationBatchChain<>(this.last(true), values); + } + } + // 啥也没,返回空 + return batchEmpty(); + } + /** * 设置上一步结果 *