From f5475190b51f3dc3be1d89981441507c52d50852 Mon Sep 17 00:00:00 2001 From: wangyu <727842003@qq.com> Date: Thu, 21 Oct 2021 20:51:12 +0800 Subject: [PATCH] =?UTF-8?q?feat=EF=BC=9A=E5=A2=9E=E5=8A=A0=E6=9F=A5?= =?UTF-8?q?=E6=89=BE=E6=9B=BF=E6=8D=A2=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/annotations/ComputedProps.java | 20 +++++++++++++++++++ .../framework/beans/meta/BeanProperty.java | 11 ++++++++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/flyfish-data/src/main/java/com/flyfish/framework/annotations/ComputedProps.java b/flyfish-data/src/main/java/com/flyfish/framework/annotations/ComputedProps.java index 848601d..064644a 100644 --- a/flyfish-data/src/main/java/com/flyfish/framework/annotations/ComputedProps.java +++ b/flyfish-data/src/main/java/com/flyfish/framework/annotations/ComputedProps.java @@ -1,31 +1,51 @@ package com.flyfish.framework.annotations; +import com.flyfish.framework.annotations.ComputedProps.List; + import java.lang.annotation.*; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + /** * 联动属性声明 + * * @author wangyu */ @Target(ElementType.FIELD) @Retention(RetentionPolicy.RUNTIME) @Documented +@Repeatable(List.class) public @interface ComputedProps { /** * 属性名 + * * @return 结果 */ String prop(); /** * 来自的字段值 + * * @return 结果 */ String field() default ""; /** * 表达式 + * * @return 结果 */ String expression() default ""; + + /** + * 可重复支持 + */ + @Target(ElementType.FIELD) + @Retention(RUNTIME) + @Documented + @interface List { + + ComputedProps[] value(); + } } 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 efa8b28..b7dc810 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 @@ -144,9 +144,16 @@ public class BeanProperty { property.extra.put(BeanProps.COMPONENT, "input-hidden"); } // 追加属性映射 - MergedAnnotation links = annotations.get(ComputedProps.class); + MergedAnnotation links = annotations.get(ComputedProps.List.class); 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 single = annotations.get(ComputedProps.class); + if (single.isPresent()) { + property.extra.put(BeanProps.LINKED, Collections.singletonList(links.asMap())); + } } // 优雅的设置额外的属性 MergedAnnotation item = annotations.get(FormItem.class);