feat:增加查找替换逻辑

This commit is contained in:
wangyu 2021-10-14 14:30:06 +08:00
parent fc707c6baa
commit d52aa851d6
2 changed files with 30 additions and 0 deletions

View File

@ -219,6 +219,8 @@ public class BeanProperty {
if (annotations.isPresent(SubBean.class)) {
// 尝试获取泛型参数存在时赋值子表单
parseSubClass(field).ifPresent(subClazz -> property.setChildren(from(subClazz)));
// 处理替换
applyReplacement(property, annotations);
} else if (annotations.isPresent(DateRange.class)) {
property.setType(BeanPropertyType.DATE);
property
@ -231,6 +233,8 @@ public class BeanProperty {
// 有子bean注解才处理
if (null != field && annotations.isPresent(SubBean.class)) {
property.setChildren(from(clazz));
// 处理替换
applyReplacement(property, annotations);
}
break;
case DB_REF:
@ -448,6 +452,21 @@ public class BeanProperty {
}
}
/**
* 替换文案的生效
*
* @param property 属性
* @param annotations 注解
*/
private static void applyReplacement(BeanProperty property, MergedAnnotations annotations) {
SubBean subBean = annotations.get(SubBean.class).synthesize();
if (CollectionUtils.isNotEmpty(property.getChildren()) && StringUtils.isNotBlank(subBean.search())
&& StringUtils.isNotBlank(subBean.replacement())) {
property.getChildren().forEach(child -> child.setTitle(child.getTitle()
.replace(subBean.search(), subBean.replacement())));
}
}
/**
* 设置当前对象的键值属性
*

View File

@ -12,4 +12,15 @@ import java.lang.annotation.*;
@Documented
@Valid
public @interface SubBean {
/**
* @return 查找字符串
*/
String search() default "";
/**
*
* @return 替换文字
*/
String replacement() default "";
}