packagecom.abliner.test.common.log;importcom.abliner.test.common.validator.InStrings;importcom.abliner.test.common.validator.ValidatorConstant;importlombok.Data;importorg.springframework.boot.context.properties.ConfigurationProperties;importorg.springframework.boot.context.properties.NestedConfigurationProperty;importorg.springframework.stereotype.Component;importjavax.validation.constraints.NotEmpty;importjava.util.List;@ConfigurationProperties(prefix ="log.record")@Data@ComponentpublicclassLogRecordConfig{privateInterfaceLogConfig defaultInterfaceLogConfig;@NestedConfigurationPropertyprivateList<InterfaceLogConfig> interfaceLogConfigs;@DatapublicstaticclassInterfaceLogConfig{@NotEmpty(groups =ValidatorConstant.InsertAndUpdate.class)@NotEmpty(groups =ValidatorConstant.Delete.class)privateString url;/***
* 1: info
* 2: debug
*/@NotEmpty(groups =ValidatorConstant.InsertAndUpdate.class)@InStrings(in={"info","debug"}, groups =ValidatorConstant.InsertAndUpdate.class)@InStrings(in={"info","debug"}, groups =ValidatorConstant.UpdateDefault.class)privateString logLevel;/***
* res
* req
* all
* none
*/@NotEmpty(groups =ValidatorConstant.InsertAndUpdate.class)@InStrings(in={"res","req","all","none"},groups =ValidatorConstant.InsertAndUpdate.class)@InStrings(in={"res","req","all","none"},groups =ValidatorConstant.UpdateDefault.class)privateString print;publicbooleanisDebugEnabled(){return"debug".equalsIgnoreCase(logLevel);}publicbooleanprintLog(){return!"none".equalsIgnoreCase(print);}publicbooleanprintRes(){return"res".equalsIgnoreCase(print)||"all".equalsIgnoreCase(print);}publicbooleanprintReq(){return"req".equalsIgnoreCase(print)||"all".equalsIgnoreCase(print);}}}
4.添加使用到的注解类InStrings.java
packagecom.abliner.test.common.validator;importjavax.validation.Constraint;importjavax.validation.Payload;importjava.lang.annotation.Documented;importjava.lang.annotation.Repeatable;importjava.lang.annotation.Retention;importjava.lang.annotation.Target;importstaticjava.lang.annotation.ElementType.*;importstaticjava.lang.annotation.ElementType.TYPE_USE;importstaticjava.lang.annotation.RetentionPolicy.RUNTIME;@Documented@Constraint(validatedBy ={InStringsValidator.class})@Target({METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER,TYPE_USE})@Retention(RUNTIME)@Repeatable(InStrings.List.class)public@interfaceInStrings{Stringmessage()default"字符串不在设定范围内";String[]in();Class<?>[]groups()default{};Class<?extendsPayload>[]payload()default{};/**
* Defines several {@code @NotEmpty} constraints on the same element.
*
* @see InStrings
*/@Target({METHOD,FIELD,ANNOTATION_TYPE,CONSTRUCTOR,PARAMETER,TYPE_USE})@Retention(RUNTIME)@Documented@interfaceList{InStrings[]value();}}