Java验证bean:验证枚举字段值

时间:2018-11-27 11:13:11

标签: java spring-boot bean-validation

我习惯于使用验证规则来检查我的其余参数:

public class ConfigurationParameterForm {

    private @NotEmpty String name;
    private @NotNull Object value;
    private @NotEmpty String beanProperty;
    private @NotEmpty String type;

}

type字段必须为以下枚举值之一:

public enum ParameterType {
    A("API"), B("BackOffice"), F("FrontOffice"), Q("Quartz"), S("Servlet");

    private String description;

    ParameterType(String description) {
        this.description = description;
    }

    public String getDescription() {
        return description;
    }
}

因此,我想检查type仅包含有效值,我的意思是ABFQ,{{ 1}}。

有什么想法吗?

0 个答案:

没有答案