@@ -88,6 +88,10 @@
|
|||||||
<groupId>com.github.ulisesbocchio</groupId>
|
<groupId>com.github.ulisesbocchio</groupId>
|
||||||
<artifactId>jasypt-spring-boot-starter</artifactId>
|
<artifactId>jasypt-spring-boot-starter</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.springframework.boot</groupId>
|
||||||
|
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
|||||||
+2
@@ -5,6 +5,7 @@ import lombok.AllArgsConstructor;
|
|||||||
import lombok.Builder;
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
|
import top.crushtj.framework.common.validator.PhoneNumber;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -25,6 +26,7 @@ public class SendVerificationCodeReqVO {
|
|||||||
* 手机号
|
* 手机号
|
||||||
*/
|
*/
|
||||||
@NotBlank(message = "手机号不能为空")
|
@NotBlank(message = "手机号不能为空")
|
||||||
|
@PhoneNumber
|
||||||
private String phoneNumber;
|
private String phoneNumber;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+28
@@ -0,0 +1,28 @@
|
|||||||
|
package top.crushtj.framework.common.validator;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ayi
|
||||||
|
* @version V1.0
|
||||||
|
* @title PhoneNumber
|
||||||
|
* @date 2026/01/18
|
||||||
|
* @description 手机号验证
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE, ElementType.PARAMETER })
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Constraint(validatedBy = PhoneNumberValidator.class)
|
||||||
|
public @interface PhoneNumber {
|
||||||
|
String message() default "手机号格式不正确, 需为 11 位数字";
|
||||||
|
|
||||||
|
Class<?>[] groups() default {};
|
||||||
|
|
||||||
|
Class<? extends Payload>[] payload() default {};
|
||||||
|
}
|
||||||
+25
@@ -0,0 +1,25 @@
|
|||||||
|
package top.crushtj.framework.common.validator;
|
||||||
|
|
||||||
|
import jakarta.validation.ConstraintValidator;
|
||||||
|
import jakarta.validation.ConstraintValidatorContext;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author ayi
|
||||||
|
* @version V1.0
|
||||||
|
* @title PhoneNumberValidator
|
||||||
|
* @date 2026/01/18 13:17
|
||||||
|
* @description 手机号验证器
|
||||||
|
*/
|
||||||
|
|
||||||
|
public class PhoneNumberValidator implements ConstraintValidator<PhoneNumber,String> {
|
||||||
|
@Override
|
||||||
|
public boolean isValid(String phoneNumber, ConstraintValidatorContext context) {
|
||||||
|
// 校验逻辑:正则表达式判断手机号是否为 11 位数字
|
||||||
|
return phoneNumber != null && phoneNumber.matches("\\d{11}");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void initialize(PhoneNumber constraintAnnotation) {
|
||||||
|
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user