feat:框架完善,增加完整的支持

This commit is contained in:
wangyu 2021-09-28 22:26:51 +08:00
parent c6682526eb
commit 1db0697340
2 changed files with 23 additions and 4 deletions

View File

@ -113,7 +113,7 @@ public class BeanProperty {
// 开始解析关键注解
if (annotations.isPresent(Property.class)) {
Property props = annotations.get(Property.class).synthesize();
// 只有存在馆建注解才会进行初始化
// 只有存在关键注解才会进行初始化
String parentName = Optional.ofNullable(beanClass.getAnnotation(RestBean.class))
.map(RestBean::name).orElse("");
property.setDescription(props.description());
@ -148,7 +148,19 @@ public class BeanProperty {
// 优雅的设置联动映射
MergedAnnotation<MappedTo> mapping = annotations.get(MappedTo.class);
if (mapping.isPresent()) {
property.extra.put("mapping", mapping.asMap());
property.extra.put(BeanProps.MAPPING, mapping.asMap());
}
// 处理联动
MergedAnnotation<ConditionOn.List> condition = annotations.get(ConditionOn.List.class);
if (condition.isPresent()) {
property.extra.put(BeanProps.CONDITION, Arrays.stream(
condition.getAnnotationArray("value", ConditionOn.class)
).map(MergedAnnotation::asMap).collect(Collectors.toList()));
} else {
MergedAnnotation<ConditionOn> single = annotations.get(ConditionOn.class);
if (single.isPresent()) {
property.extra.put(BeanProps.CONDITION, Collections.singletonList(single.asMap()));
}
}
// 优雅的处理校验
property.setValidation(ValidationCandidate.produce(annotations));
@ -190,7 +202,7 @@ public class BeanProperty {
break;
case NUMBER:
if (null != field) {
if (annotations.isPresent(Money.class) && !property.extra.containsKey("component")) {
if (annotations.isPresent(Money.class) && !property.extra.containsKey(BeanProps.COMPONENT)) {
property.extra.put(BeanProps.COMPONENT, "money-input");
}
}
@ -328,13 +340,16 @@ public class BeanProperty {
}
// 处理额外的映射
if (ArrayUtils.isNotEmpty(prop.mapping())) {
property.extra.put("mapping", MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
property.extra.put(BeanProps.MAPPING, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
}
// 处理值生成策略此处可清除原策略
if (ArrayUtils.isNotEmpty(prop.generated())) {
property.extra.put(BeanProps.GENERATED, MergedAnnotations.from(prop.mapping()).get(MappedTo.class).asMap());
} else {
property.extra.remove(BeanProps.GENERATED);
if ("input-hidden".equals(property.extra.get(BeanProps.COMPONENT))) {
property.extra.remove(BeanProps.COMPONENT);
}
}
// 设置标题
property.title = prop.title();

View File

@ -21,4 +21,8 @@ public interface BeanProps {
String COMPONENT = "component";
String GENERATED = "generated";
String MAPPING = "mapping";
String CONDITION = "condition";
}