Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

支持 @AssembleConstant 注解,用于快速声明一个基于常量类的装配操作 #135

Closed
Createsequence opened this issue Aug 19, 2023 · 0 comments
Labels
enhancement New feature or request
Milestone

Comments

@Createsequence
Copy link
Collaborator

Createsequence commented Aug 19, 2023

提供一个 @AssembleConstant 注解,用于基于静态常量完成填充。比如:

public class Foo {

    @AssembleConstant(
        type = Constant.class, // 指定常量类
        props = @Mapping(ref = "name") // 将值映射到 `name` 属性
    )
    private Integer value;
    private String name;
}

并且,该注解应当支持引用对象中的 Map 集合或者 Collection 集合的属性,比如:

public class Foo {

    @AssembleConstant(
        type = Constant.class, // 指定常量类
        on = "STRATEGIES_MAP"
        props = @Mapping(ref = "name") // 将值映射到 `name` 属性
    )
    private Integer value;
    private String name;
}

public static final class Constant {
    private static final Map<String, Strategy> STRATEGIES_MAP = new HashMap<>();
}

此处可参照 @AssembleMethod,支持从 Spring 容器中获得 Bean。

其中,对于 @AssembleConstant 注解:

  • 注解应当跟其他的标准注解一样,支持包括 sortprops 在内的各种标准属性;
  • 注解应当像 @AssembleEnum 一样,支持可选是否要遵循 @ConstantContainer 上的配置;

该功能可参考 @Assemble 注解与其对应的解析器 AssembleAnnotationHandler 完成。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant