feat: 添加模糊批量元数据遍历
This commit is contained in:
parent
9be28a426b
commit
6f7bb3cbea
@ -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);
|
||||
|
||||
/**
|
||||
* 设置上一步结果
|
||||
*
|
||||
|
@ -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();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置上一步结果
|
||||
*
|
||||
|
Loading…
x
Reference in New Issue
Block a user