feat:增加查找替换逻辑
This commit is contained in:
parent
fc707c6baa
commit
d52aa851d6
@ -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())));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置当前对象的键值属性
|
||||
*
|
||||
|
@ -12,4 +12,15 @@ import java.lang.annotation.*;
|
||||
@Documented
|
||||
@Valid
|
||||
public @interface SubBean {
|
||||
|
||||
/**
|
||||
* @return 查找字符串
|
||||
*/
|
||||
String search() default "";
|
||||
|
||||
/**
|
||||
*
|
||||
* @return 替换文字
|
||||
*/
|
||||
String replacement() default "";
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user