feat: 添加模糊批量元数据遍历

This commit is contained in:
wangyu 2024-11-29 10:16:35 +08:00
parent 9be28a426b
commit 6f7bb3cbea
2 changed files with 46 additions and 0 deletions

View File

@ -74,6 +74,18 @@ public interface BeanPropertyAnnotations {
<A extends Annotation, L extends Annotation> BeanPropertyAnnotationBatchChain<A, MergedAnnotation<A>> as(
Class<A> annotationType, Class<L> listType);
/**
* 判断某个注解是否存在存在则交给consumer进行处理取得所有注解并自动判断复数形式
*
* @param annotationType 注解类型
* @param listType 列表类型
* @param <A> 泛型
* @param <L> 列表泛型
* @return 结果
*/
<A extends Annotation, L extends Annotation> BeanPropertyAnnotationBatchChain<A, MergedAnnotation<A>> as(
String annotationType, String listType);
/**
* 设置上一步结果
*

View File

@ -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 <A extends Annotation, L extends Annotation> BeanPropertyAnnotationBatchChain<A, MergedAnnotation<A>> as(String annotationType, String listType) {
if (null != field && !this.last) {
MergedAnnotation<L> annotation = this.annotations.get(listType);
// 存在注解容器读取之
if (annotation.isPresent()) {
List<MergedAnnotation<A>> picked = annotation.getValue("value")
.map(value -> Arrays.asList((MergedAnnotation<A>[]) value))
.orElse(Collections.emptyList());
if (!CollectionUtils.isEmpty(picked)) {
return new SimpleAnnotationBatchChain<>(this.last(true), picked);
}
}
// 不存在或为空查找直接注解的大多数是一个
List<MergedAnnotation<A>> values = this.annotations.<A>stream(annotationType)
.filter(MergedAnnotation::isPresent)
.collect(Collectors.toList());
if (!CollectionUtils.isEmpty(values)) {
return new SimpleAnnotationBatchChain<>(this.last(true), values);
}
}
// 啥也没返回空
return batchEmpty();
}
/**
* 设置上一步结果
*