有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

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

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

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是否只包含有效值,我的意思是ABFQS

有什么想法吗


共 (0) 个答案