-
Notifications
You must be signed in to change notification settings - Fork 33
分组过滤
huangchengxing edited this page Feb 15, 2023
·
1 revision
通过 @Assemble
与 @Disassemble
注解声明的操作皆可通过 groups
属性指定分组:
public class UserVO {
@Assemble(namespace = "user", props = @Mapping(src = "role", ref = "role"), groups = "admin")
@Assemble(namespace = "user", props = @Mapping(src = "name", ref = "name"), groups = {"base", "admin"})
private Integer id;
private String name;
private String role;
}
比如,在上述示例中,我们在 UserVO.id
声明了两个装配操作,一个是根据 id
装配 name
,另一个是根据 id
装配 role
,当我们指定 groups
不带有 admin
时,将会只执行 name
的装配。
@Disassemble
注解亦同:
public class Foo {
@Assemble(namespace = "user", props = @Mapping(src = "name", ref = "name"), groups = "admin")
private Integer id;
private String name;
@Disassemble(type = Foo.class, groups = "nested")
private List<Foo> fooList;
}
当手动填充时,可通过 OperateTemplate
的指定重载方法设置本次填充操作的执行组:
executeIfMatchAnyGroups(Object target, String... groups);
executeIfNoneMatchAnyGroups(Object target, String... groups);
executeIfMatchAllGroups(Object target, String... groups);
execute(Object target, Predicate<? super KeyTriggerOperation> filter);
当自动填充时,可以在 @AutoOperate
注解中指定操作组:
// 填充返回值
@AutoOperate(type = Foo.class, groups = "base")
public List<Foo> getFooList() {
// do nothing
}
// 填充参数
@ArgAutoOperate(
@AutoOperate(value = "foos", type = Foo.class, groups = "base")
)
public void setFooList(List<Foo> foos) {
// do nothing
}