自定义注解校验
parent
e7355f9604
commit
6f03aa309f
5
pom.xml
5
pom.xml
|
@ -164,6 +164,11 @@
|
|||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>io.swagger.core.v3</groupId>
|
||||
<artifactId>swagger-annotations-jakarta</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
package com.muyu.common.core.enums;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.core.enums
|
||||
* @Project:cloud-common-core
|
||||
* @name:SystemYesNo
|
||||
* @Date:2024/8/1 10:41
|
||||
*/
|
||||
public enum SystemYesNo {
|
||||
YES("Y","是"),NO("N","否");
|
||||
|
||||
private final String code;
|
||||
private final String info;
|
||||
|
||||
SystemYesNo(String code, String info) {
|
||||
this.code = code;
|
||||
this.info = info;
|
||||
}
|
||||
|
||||
public String getCode () {
|
||||
return code;
|
||||
}
|
||||
|
||||
public String getInfo () {
|
||||
return info;
|
||||
}
|
||||
|
||||
public static boolean isCode(String code){
|
||||
return Arrays.stream(values())
|
||||
.map(SystemYesNo::getCode)
|
||||
.anyMatch(s -> s.equals(code));
|
||||
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import jakarta.validation.Constraint;
|
||||
|
||||
import java.lang.annotation.*;
|
||||
|
||||
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.core.validation.custom
|
||||
* @Project:cloud-common-core
|
||||
* @name:IsSystemYesNo
|
||||
* @Date:2024/8/1 10:59
|
||||
*/
|
||||
@Target({ElementType.FIELD})
|
||||
@Retention(RUNTIME)
|
||||
@Documented
|
||||
@Constraint(validatedBy = SystemYsNoValidator.class)
|
||||
public @interface IsSystemYesNo {
|
||||
|
||||
String message() default "数据字典:[系统是否] - 参数不合法";
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.muyu.common.core.validation.custom;
|
||||
|
||||
import com.muyu.common.core.enums.SystemYesNo;
|
||||
import jakarta.validation.ConstraintValidator;
|
||||
import jakarta.validation.ConstraintValidatorContext;
|
||||
|
||||
/**
|
||||
* @Author:张腾
|
||||
* @Package:com.muyu.common.core.validation.custom
|
||||
* @Project:cloud-common-core
|
||||
* @name:SystemYsNoValidator
|
||||
* @Date:2024/8/1 11:29
|
||||
*/
|
||||
public class SystemYsNoValidator implements ConstraintValidator<IsSystemYesNo,String> {
|
||||
|
||||
@Override
|
||||
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||
return SystemYesNo.isCode(value);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue