han-note项目初始化完毕!
- 自定义邮箱校验注解
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package com.hanserwei.hannote.auth.model.vo;
|
package com.hanserwei.hannote.auth.model.vo;
|
||||||
|
|
||||||
|
import com.hanserwei.framework.common.validate.EmailNumber;
|
||||||
import jakarta.validation.constraints.NotBlank;
|
import jakarta.validation.constraints.NotBlank;
|
||||||
import lombok.AllArgsConstructor;
|
import lombok.AllArgsConstructor;
|
||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
@@ -13,6 +14,7 @@ import lombok.NoArgsConstructor;
|
|||||||
public class SendVerificationCodeReqVO {
|
public class SendVerificationCodeReqVO {
|
||||||
|
|
||||||
@NotBlank(message = "邮箱不能为空")
|
@NotBlank(message = "邮箱不能为空")
|
||||||
|
@EmailNumber
|
||||||
private String email;
|
private String email;
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package com.hanserwei.framework.common.validate;
|
||||||
|
|
||||||
|
import jakarta.validation.Constraint;
|
||||||
|
import jakarta.validation.Payload;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
|
||||||
|
@Target({ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Constraint(validatedBy = EmailValidator.class)
|
||||||
|
public @interface EmailNumber {
|
||||||
|
|
||||||
|
String message() default "邮箱格式不正确,请检查!";
|
||||||
|
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package com.hanserwei.framework.common.validate;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
public class EmailValidator implements ConstraintValidator<EmailNumber, String> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(EmailNumber constraintAnnotation) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String emailNumber, ConstraintValidatorContext constraintValidatorContext) {
|
||||||
|
return emailNumber != null && emailNumber.matches("^\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*\\.\\w+([-.]\\w+)*$");
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user