parent
9ef8ec7a6b
commit
cf59446afc
@ -0,0 +1,13 @@
|
|||||||
|
package jty.expressdistributionsystem.validation;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
import jty.expressdistributionsystem.validation.inter.ValidQuality;
|
||||||
|
|
||||||
|
public class QualityValidator implements ConstraintValidator<ValidQuality, Double> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(Double value, ConstraintValidatorContext context) {
|
||||||
|
return value != null && value > 0; // 确保数值不为null且大于0
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package jty.expressdistributionsystem.validation.inter;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
import jty.expressdistributionsystem.validation.QualityValidator;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Constraint(validatedBy = QualityValidator.class) // 指定验证器
|
||||||
|
@Target({ ElementType.FIELD, ElementType.METHOD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface ValidQuality {
|
||||||
|
String message() default "快递重量必须大于0";
|
||||||
|
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
Loading…
Reference in new issue