增加系统字典校验
parent
868a4c903a
commit
42db9b9e02
|
@ -0,0 +1,51 @@
|
||||||
|
package com.muyu.common.core.enums;
|
||||||
|
|
||||||
|
import java.lang.reflect.Array;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangchengzhi
|
||||||
|
* @Package:com.muyu.common.core.enums
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:SystemYesNo
|
||||||
|
* @Date:2024/7/31 20:07
|
||||||
|
*/
|
||||||
|
public enum SystemYesNo {
|
||||||
|
YES("Y","是"),
|
||||||
|
NO("N","否")
|
||||||
|
;
|
||||||
|
|
||||||
|
private final String code;
|
||||||
|
private final String info;
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInfo() {
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
SystemYesNo(String code, String info) {
|
||||||
|
this.code = code;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 鉴别Code是否合法
|
||||||
|
* @param code
|
||||||
|
* @return 如果存在code则返回true,不存在则返回
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static boolean isCode(String code){
|
||||||
|
|
||||||
|
return Arrays.stream(values())
|
||||||
|
.map(SystemYesNo::getCode)
|
||||||
|
.anyMatch(s -> s.equals(code)); //传cou
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,24 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
|
||||||
|
import java.lang.annotation.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangchengzhi
|
||||||
|
* @Package:com.muyu.common.core.validation.custom
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:IsSystemYesNo
|
||||||
|
* @Date:2024/7/31 20:22
|
||||||
|
*/
|
||||||
|
@Target({ElementType.FIELD})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Documented
|
||||||
|
@Constraint(validatedBy = {SystemYesNoValidator.class})
|
||||||
|
public @interface IsSystemYesNo {
|
||||||
|
|
||||||
|
String message() default "数据字典: [系统是否] - 参数不合法";
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,21 @@
|
||||||
|
package com.muyu.common.core.validation.custom;
|
||||||
|
|
||||||
|
import com.muyu.common.core.enums.SystemYesNo;
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
import jakarta.validation.Validator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Author:zhangchengzhi
|
||||||
|
* @Package:com.muyu.common.core.validation.custom
|
||||||
|
* @Project:cloud-common-core
|
||||||
|
* @name:SystemYesNoValidator
|
||||||
|
* @Date:2024/7/31 20:22
|
||||||
|
*/
|
||||||
|
public class SystemYesNoValidator implements ConstraintValidator<IsSystemYesNo,String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String value, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
return SystemYesNo.isCode(value);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue