feat:增加查找替换逻辑

This commit is contained in:
wangyu 2021-10-21 20:51:12 +08:00
parent 973040f363
commit f5475190b5
2 changed files with 29 additions and 2 deletions

View File

@ -1,31 +1,51 @@
package com.flyfish.framework.annotations; package com.flyfish.framework.annotations;
import com.flyfish.framework.annotations.ComputedProps.List;
import java.lang.annotation.*; import java.lang.annotation.*;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/** /**
* 联动属性声明 * 联动属性声明
*
* @author wangyu * @author wangyu
*/ */
@Target(ElementType.FIELD) @Target(ElementType.FIELD)
@Retention(RetentionPolicy.RUNTIME) @Retention(RetentionPolicy.RUNTIME)
@Documented @Documented
@Repeatable(List.class)
public @interface ComputedProps { public @interface ComputedProps {
/** /**
* 属性名 * 属性名
*
* @return 结果 * @return 结果
*/ */
String prop(); String prop();
/** /**
* 来自的字段值 * 来自的字段值
*
* @return 结果 * @return 结果
*/ */
String field() default ""; String field() default "";
/** /**
* 表达式 * 表达式
*
* @return 结果 * @return 结果
*/ */
String expression() default ""; String expression() default "";
/**
* 可重复支持
*/
@Target(ElementType.FIELD)
@Retention(RUNTIME)
@Documented
@interface List {
ComputedProps[] value();
}
} }

View File

@ -144,9 +144,16 @@ public class BeanProperty {
property.extra.put(BeanProps.COMPONENT, "input-hidden"); property.extra.put(BeanProps.COMPONENT, "input-hidden");
} }
// 追加属性映射 // 追加属性映射
MergedAnnotation<ComputedProps> links = annotations.get(ComputedProps.class); MergedAnnotation<ComputedProps.List> links = annotations.get(ComputedProps.List.class);
if (links.isPresent()) { if (links.isPresent()) {
property.extra.put(BeanProps.LINKED, links.asMap()); property.extra.put(BeanProps.LINKED, Arrays.stream(
links.getAnnotationArray("value", ComputedProps.class)
).map(MergedAnnotation::asMap).collect(Collectors.toList()));
} else {
MergedAnnotation<ComputedProps> single = annotations.get(ComputedProps.class);
if (single.isPresent()) {
property.extra.put(BeanProps.LINKED, Collections.singletonList(links.asMap()));
}
} }
// 优雅的设置额外的属性 // 优雅的设置额外的属性
MergedAnnotation<FormItem> item = annotations.get(FormItem.class); MergedAnnotation<FormItem> item = annotations.get(FormItem.class);