mirror of
http://192.168.1.205:9980/cf_devdept2/cf_imes_server.git
synced 2026-08-12 21:02:08 +08:00
@Mobile校验优化,支持自定义提示
This commit is contained in:
+8
@@ -3,6 +3,7 @@ package com.cf.imes.framework.common.validation;
|
||||
import cn.hutool.core.text.CharSequenceUtil;
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import com.cf.imes.framework.common.util.validation.ValidationUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.validation.ConstraintValidator;
|
||||
import javax.validation.ConstraintValidatorContext;
|
||||
@@ -11,10 +12,13 @@ public class MobileValidator implements ConstraintValidator<Mobile, String> {
|
||||
|
||||
private String[] ignoreWhenCheck;
|
||||
|
||||
private String message;
|
||||
|
||||
@Override
|
||||
public void initialize(Mobile constraintAnnotation) {
|
||||
ConstraintValidator.super.initialize(constraintAnnotation);
|
||||
this.ignoreWhenCheck = constraintAnnotation.ignoreWhenCheck();
|
||||
this.message = constraintAnnotation.message();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -26,6 +30,10 @@ public class MobileValidator implements ConstraintValidator<Mobile, String> {
|
||||
if (CharSequenceUtil.isEmpty(value)) {
|
||||
return true;
|
||||
}
|
||||
if (StringUtils.isNotEmpty(message)) {
|
||||
context.disableDefaultConstraintViolation(); // 禁用默认的 message 的值
|
||||
context.buildConstraintViolationWithTemplate(message).addConstraintViolation();
|
||||
}
|
||||
// 校验手机
|
||||
return ValidationUtils.isMobile(value);
|
||||
}
|
||||
|
||||
+1
-1
@@ -112,7 +112,7 @@ public class AuthController {
|
||||
@OperateLog(enable = false)
|
||||
@Parameter(name = "mobile", description = "手机号", required = true)
|
||||
public CommonResult<Boolean> loginCheck(
|
||||
@Param("mobile") @NotEmpty(message = "手机号不能为空") @Mobile(ignoreWhenCheck = {"admin"}) String mobile) {
|
||||
@Param("mobile") @NotEmpty(message = "手机号不能为空") @Mobile(message = "账号密码不正确,请重新输入", ignoreWhenCheck = {"admin"}) String mobile) {
|
||||
return success(authService.loginCheck(mobile));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user