1. 参数校验支持国际化

This commit is contained in:
黄昕 2024-03-25 16:07:21 +08:00
parent e654fc3fe5
commit b446d327b1
20 changed files with 109 additions and 67 deletions

View File

@ -2,7 +2,9 @@ package com.cf.cs.base.config;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.support.ReloadableResourceBundleMessageSource;
import org.springframework.context.support.ResourceBundleMessageSource;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import java.util.Locale;
@ -30,4 +32,13 @@ public class LocaleConfig {
source.setDefaultEncoding("UTF-8");
return source;
}
@Bean
public LocalValidatorFactoryBean localValidatorFactoryBean() {
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
ReloadableResourceBundleMessageSource messageSource = new ReloadableResourceBundleMessageSource();
messageSource.setBasename("i18n/validationMessage");
localValidatorFactoryBean.setValidationMessageSource(messageSource);
return localValidatorFactoryBean;
}
}

View File

@ -7,9 +7,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.validation.ConstraintViolation;
import jakarta.validation.Validation;
import jakarta.validation.ValidatorFactory;
import org.hibernate.validator.HibernateValidator;
import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import java.io.IOException;
import java.io.InputStream;
@ -26,6 +25,7 @@ import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
@ -35,12 +35,12 @@ import java.util.Set;
* @author xajhuang @163.com
*/
public class HelperUtils {
private static final ObjectMapper OBJ_MAPPER = ObjectMapperProvider.getMapper();
private HelperUtils() {
throw new AssertionError("Instantiating utility class.");
}
private static final ObjectMapper OBJ_MAPPER = ObjectMapperProvider.getMapper();
/**
* Gets json.
*
@ -155,15 +155,13 @@ public class HelperUtils {
*/
public static <T> List<String> validate(T t, Class<?>... groups) {
Set<ConstraintViolation<T>> set;
ValidatorFactory validatorFactory = Validation.byProvider(HibernateValidator.class)
.configure()
.failFast(false)
.buildValidatorFactory();
LocaleContextHolder.setLocale(Locale.forLanguageTag(ApiContextUtils.getLanguare().replace('_', '-')));
LocalValidatorFactoryBean localValidatorFactory = SpringBootBeanUtils.getBean(LocalValidatorFactoryBean.class);
if (groups != null && groups.length > 0) {
set = validatorFactory.getValidator().validate(t, groups);
set = localValidatorFactory.getValidator().validate(t, groups);
} else {
set = validatorFactory.getValidator().validate(t);
set = localValidatorFactory.getValidator().validate(t);
}
List<String> validateError = new ArrayList<>();
if (!set.isEmpty()) {

View File

@ -0,0 +1,14 @@
item.not_null=field cannot be null
item.not_empty=field cannot be empty string
item.value_range=Field value range [{min}, {max}]
item.value_min=Minimum value is {min}
array.value_range=Array/List size range [{min}, {max}]
array.not_empty=Arrays/List cannot be NULL and elements cannot be empty
timestamp.timeout=The difference between the field value and the current time cannot be greater than the timeout configuration
page.item_size=The value must be an integer multiple of 5
uuid.format=UUID string must match format(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)
invalid.character=Invalid character strings exist
password.length=The password size must be SHA256 length
http.request_invalid=Not a legitimate HTTP request method
timeout.current.format=Request time[{0}] greater than current server time[{1}]
timeout.server.format=Request time [{0}] Delay exceeds current server time [{1}] Allowed range {2}(S)

View File

@ -0,0 +1,14 @@
item.not_null=\u5B57\u6BB5\u4E0D\u80FD\u4E3A NULL
item.not_empty=\u5B57\u6BB5\u4E0D\u80FD\u4E3A\u7A7A\u5B57\u7B26\u4E32
item.value_range=\u5B57\u6BB5\u53D6\u503C\u8303\u56F4 [{min}, {max}]
item.value_min=\u6700\u5C0F\u503C\u4E3A {min}
array.value_range=\u6570\u7EC4/\u94FE\u8868\u5143\u7D20\u4E2A\u6570\u53D6\u503C\u8303\u56F4 [{min}, {max}]
array.not_empty=\u6570\u7EC4/\u94FE\u8868\u4E0D\u80FD\u4E3ANULL\u4E14\u5143\u7D20\u4E0D\u80FD\u4E3A\u7A7A
timestamp.timeout=\u5B57\u6BB5\u503C\u4E0E\u5F53\u524D\u65F6\u95F4\u5DEE\u4E0D\u80FD\u5927\u4E8E\u8D85\u65F6\u914D\u7F6E
page.item_size=\u53D6\u503C\u5FC5\u987B\u4E3A 5 \u7684\u6574\u6570\u500D
uuid.format=\u5FC5\u987B\u4E3A\u7B26\u5408UUID\u89C4\u8303(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)\u7684\u5B57\u7B26\u4E32
invalid_character=\u5B57\u7B26\u4E32\u5B58\u5728\u975E\u6CD5\u5B57\u7B26
password.length=\u5BC6\u7801\u957F\u5EA6\u5FC5\u987B\u4E3ASHA256\u7F16\u7801\u540E\u7684\u957F\u5EA6
http.request_invalid=\u4E0D\u662F\u5408\u6CD5\u7684 HTTP \u8BF7\u6C42\u65B9\u6CD5
timeout.current.format=\u8BF7\u6C42\u65F6\u95F4[{0}] \u5927\u4E8E\u5F53\u524D\u670D\u52A1\u5668\u65F6\u95F4[{1}]
timeout.server.format=\u8BF7\u6C42\u65F6\u95F4[{0}] \u5EF6\u65F6\u8D85\u8FC7\u5F53\u524D\u670D\u52A1\u5668\u65F6\u95F4[{1}] \u5141\u8BB8\u8303\u56F4 {2}(S)

View File

@ -30,16 +30,16 @@ public class BaseProtocol<T> implements Serializable {
@Serial
private static final long serialVersionUID = -32326523643641L;
@NotNull(message = "ver 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
@Range(min = 1, max = 9999, message = "ver 字段最小值为 1", groups = ValidGroups.ProtocolCommonValid.class)
@NotNull(message = "ver {item.not_null}", groups = ValidGroups.ProtocolCommonValid.class)
@Range(min = 1, max = 9999, message = "ver {item.value_range}", groups = ValidGroups.ProtocolCommonValid.class)
private Integer ver;
@NotNull(message = "cryptoType 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
@Range(min = 0, max = 4, message = "cryptoType 字段取值为 [0, 4]", groups = ValidGroups.ProtocolCommonValid.class)
@NotNull(message = "cryptoType {item.not_null}", groups = ValidGroups.ProtocolCommonValid.class)
@Range(min = 0, max = 4, message = "cryptoType {item.value_range}", groups = ValidGroups.ProtocolCommonValid.class)
private Integer cryptoType;
@NotNull(message = "timeStamp 字段不能为空", groups = ValidGroups.ProtocolCommonValid.class)
@ValidProtocolTimestamp(message = "timeStamp 字段值与当前时间差不能大于超时配置", groups = ValidGroups.ProtocolCommonValid.class)
@NotNull(message = "timeStamp {item.not_null}", groups = ValidGroups.ProtocolCommonValid.class)
@ValidProtocolTimestamp(message = "timeStamp {timestamp.timeout}", groups = ValidGroups.ProtocolCommonValid.class)
private Long timeStamp;
@Valid

View File

@ -27,10 +27,10 @@ import java.util.List;
@Schema(name = "AddDictContentReq", description = "新增用户字典内容请求参数")
@JsonInclude(JsonInclude.Include.NON_NULL)
public class AddDictContentReq {
@NotBlank(message = "dictTpe 字典名称不能为空", groups = ValidGroups.DictReqValid.class)
@NotBlank(message = "dictTpe {item.not_empty}", groups = ValidGroups.DictReqValid.class)
private String dictName;
@NotNull(message = "dictContent 字典内容值不能为 NULL", groups = ValidGroups.DictReqValid.class)
@Size(min = 1, max = 100, message = "字典内容至少需要指定 1 个,最多只能指定 100 个", groups = ValidGroups.DictReqValid.class)
@NotNull(message = "dictContent {item.not_null}", groups = ValidGroups.DictReqValid.class)
@Size(min = 1, max = 100, message = "DictDetails {array.value_range}", groups = ValidGroups.DictReqValid.class)
private List<@Valid DictDetails> dictContent;
}

View File

@ -4,12 +4,12 @@ import com.cf.cs.protocol.validation.group.ValidGroups;
import com.cf.cs.protocol.validation.valids.ValidPageSize;
import com.fasterxml.jackson.annotation.JsonInclude;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.validator.constraints.Range;
/**
* The type Base paged req.
@ -23,15 +23,14 @@ import lombok.NoArgsConstructor;
@Schema(name = "BasePagedReq", description = "分页请求基础参数")
public class BasePagedReq {
@Schema(description = "分页号最小值为1")
@NotNull(message = "pageNumber 必须指定分页配置", groups = ValidGroups.BasePagedReqValid.class)
@NotNull(message = "pageNumber {item.not_null}", groups = ValidGroups.BasePagedReqValid.class)
@Min(value = 1, message = "pageNumber 最小值为1", groups = ValidGroups.BasePagedReqValid.class)
private Long pageNumber;
@Schema(description = "分页大小最小值为5 最大值100 取值必须为5的整数倍")
@NotNull(message = "pageSize 必须指定分页配置", groups = ValidGroups.BasePagedReqValid.class)
@ValidPageSize(message = "pageSize 取值必须为 5 的整数倍", groups = ValidGroups.BasePagedReqValid.class)
@Min(value = 5, message = "pageSize 最小值为5", groups = ValidGroups.BasePagedReqValid.class)
@Max(value = 100, message = "pageSize 最大值为100", groups = ValidGroups.BasePagedReqValid.class)
@NotNull(message = "pageSize {item.not_null}", groups = ValidGroups.BasePagedReqValid.class)
@ValidPageSize(message = "pageSize {page.item_size}", groups = ValidGroups.BasePagedReqValid.class)
@Range(min = 5, max = 100, message = "pageSize {item.value_range}", groups = ValidGroups.BasePagedReqValid.class)
private Long pageSize;
@Schema(description = "数据总数未知时可以为空或者小于0 存在时可以加快后端数据库查询速度")

View File

@ -26,7 +26,7 @@ import java.util.List;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class DictContentReq {
@Schema(description = "字典名")
@NotNull(message = "dictTpe 字典名称不能为NULL", groups = ValidGroups.DictReqValid.class)
@Size(min = 1, max = 100, message = "dictTpe 单次查询字典名称条数为 [1, 100]", groups = ValidGroups.DictReqValid.class)
@NotNull(message = "dictTpe {item.not_null}", groups = ValidGroups.DictReqValid.class)
@Size(min = 1, max = 100, message = "dictTpe {array.value_range}", groups = ValidGroups.DictReqValid.class)
private List<@NotBlank(message = "dictTpe 字典名称不能为空", groups = ValidGroups.DictReqValid.class) String> dictTpe;
}

View File

@ -26,10 +26,10 @@ public class IdArrayReq {
/**
* The Ids.
*/
@NotNull(message = "ids 不能为 NULL", groups = ValidGroups.UserIdReqValid.class)
@Size(min = 1, max = 100, message = "ids 元素个数最小为1 最大为100", groups = ValidGroups.UserIdReqValid.class)
List<@NotBlank(message = "guid 不能为空", groups = ValidGroups.UserIdReqValid.class)
@NotNull(message = "ids {item.not_null}", groups = ValidGroups.UserIdReqValid.class)
@Size(min = 1, max = 100, message = "ids {array.value_range}", groups = ValidGroups.UserIdReqValid.class)
List<@NotBlank(message = "guid {item.not_empty}", groups = ValidGroups.UserIdReqValid.class)
@Pattern(regexp = "^[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$",
message = "uid 必须为符号UUID规范(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)的字符串", groups = ValidGroups.UserIdReqValid.class)
message = "uid {uuid.format}", groups = ValidGroups.UserIdReqValid.class)
String> ids;
}

View File

@ -22,23 +22,23 @@ import org.hibernate.validator.constraints.Length;
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class LoginReq {
@NotBlank(message = "username 用户名不能为空", groups = ValidGroups.LogoutReqValid.class)
@NotBlank(message = "username {item.not_empty}", groups = ValidGroups.LogoutReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE,
message = "username 用户名存在非法字符串",
message = "username {invalid.character}",
groups = ValidGroups.LogoutReqValid.class)
private String username;
/**
* The Password.
*/
@NotBlank(message = "password 密码不能为空", groups = ValidGroups.LoginReqValid.class)
@NotBlank(message = "password {item.not_empty}", groups = ValidGroups.LoginReqValid.class)
@Length(min = 32, max = 64,
message = "password 密码长度必须为SHA256编码后的长度",
message = "password {password.length}",
groups = ValidGroups.LoginReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE,
message = "password 密码存在非法字符串",
message = "password {invalid.character}",
groups = ValidGroups.LoginReqValid.class)
private String password;
}

View File

@ -23,14 +23,14 @@ import lombok.NoArgsConstructor;
@Schema(name = "NewUserDictReq", description = "新增用户字典请求参数")
public class NewUserDictReq {
@Schema(description = "字典名,用于标识各个不同的字典")
@NotEmpty(message = "dictName 字典类别不能为空", groups = ValidGroups.DictReqValid.class)
@NotEmpty(message = "dictName {item.not_empty}", groups = ValidGroups.DictReqValid.class)
private String dictName;
@Schema(description = "字典别名,用于显示字典别名")
@NotNull(message = "dictAlias 字典类别不能为NULL", groups = ValidGroups.DictReqValid.class)
@NotNull(message = "dictAlias {item.not_null}", groups = ValidGroups.DictReqValid.class)
private String dictAlias;
@Schema(description = "字典备注信息")
@NotNull(message = "dictRemark 字典类别不能为NULL", groups = ValidGroups.DictReqValid.class)
@NotNull(message = "dictRemark {item.not_null}", groups = ValidGroups.DictReqValid.class)
private String dictRemark;
}

View File

@ -25,7 +25,7 @@ import java.util.List;
@Schema(name = "OperationLogDetailsReq", description = "操作日志详细请求参数")
public class OperationLogDetailsReq {
@Schema(description = "操作日志ID")
@NotEmpty(message = "操作日志ID不能为空", groups = ValidGroups.OperationLogReqValid.class)
@Size(message = "操作日志ID至少需要指定 1 个,最多只能指定 100 个", min = 1, max = 100, groups = ValidGroups.OperationLogReqValid.class)
@NotEmpty(message = "{array.not_empty}", groups = ValidGroups.OperationLogReqValid.class)
@Size(message = "{array.value_range}", min = 1, max = 100, groups = ValidGroups.OperationLogReqValid.class)
private List<Long> operationIds;
}

View File

@ -30,7 +30,7 @@ public class RegisterResourceReq {
* The Resources.
*/
@Schema(description = "需要添加的资源")
@NotNull(message = "resources 资源不能为NULL", groups = ValidGroups.ResourceReqValid.class)
@Size(min = 1, max = 100, message = "resources 单次添加资源条数为 [1, 100]", groups = ValidGroups.ResourceReqValid.class)
@NotNull(message = "resources {item.not_null}", groups = ValidGroups.ResourceReqValid.class)
@Size(min = 1, max = 100, message = "resources {array.value_range}", groups = ValidGroups.ResourceReqValid.class)
List<@Valid ResourceInfo> resources;
}

View File

@ -24,26 +24,26 @@ import org.hibernate.validator.constraints.Length;
@JsonInclude(JsonInclude.Include.NON_NULL)
public class RegisterUserReq {
@Schema(description = "用户名")
@NotBlank(message = "username 用户名不能为空", groups = ValidGroups.UserReqValid.class)
@NotBlank(message = "username {item.not_empty}", groups = ValidGroups.UserReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE,
message = "username 用户名存在非法字符串",
message = "username {invalid.character}",
groups = ValidGroups.UserReqValid.class)
private String username;
@Schema(description = "密码")
@NotBlank(message = "password 密码不能为空", groups = ValidGroups.UserReqValid.class)
@NotBlank(message = "password {item.not_empty}", groups = ValidGroups.UserReqValid.class)
@Length(min = 32, max = 64,
message = "password 密码长度必须为SHA256编码后的长度",
message = "password {password.length}",
groups = ValidGroups.UserReqValid.class)
@Pattern(regexp = ConstValue.UN_EXPECT_REGEX_CHARS,
flags = Pattern.Flag.CASE_INSENSITIVE,
message = "password 密码存在非法字符串",
message = "password {invalid.character}",
groups = ValidGroups.UserReqValid.class)
private String password;
@Schema(description = "用户组ID")
@NotNull(message = "roleId 用户组ID不能为空", groups = ValidGroups.UserReqValid.class)
@Min(value = 2, message = "roleId 用户组ID最小取值为2", groups = ValidGroups.UserReqValid.class)
@NotNull(message = "roleId {item.not_null}", groups = ValidGroups.UserReqValid.class)
@Min(value = 2, message = "roleId {item.value_min}", groups = ValidGroups.UserReqValid.class)
private Long roleId;
}

View File

@ -22,6 +22,6 @@ import lombok.NoArgsConstructor;
@Schema(name = "RemoveDictReq", description = "删除用户字典请求参数")
public class RemoveDictReq {
@Schema(description = "字典名,用于标识各个不同的字典")
@NotNull(message = "dictName 字典名不能为NULL", groups = ValidGroups.DictReqValid.class)
@NotNull(message = "dictName {item.not_null}", groups = ValidGroups.DictReqValid.class)
private String dictName;
}

View File

@ -20,7 +20,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@JsonInclude(JsonInclude.Include.NON_NULL)
public class UserIdReq {
@NotNull(message = "userId 用户ID不能为空", groups = ValidGroups.UserIdReqValid.class)
@UUID(message = "uid 必须为符号UUID规范(xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx)的字符串", groups = ValidGroups.UserIdReqValid.class)
@NotNull(message = "userId {item.not_null}", groups = ValidGroups.UserIdReqValid.class)
@UUID(message = "uid {uuid.format}", groups = ValidGroups.UserIdReqValid.class)
private String uid;
}

View File

@ -31,9 +31,9 @@ public class DictDetails {
private String upgradeBy;
private Timestamp upgradeTime;
@NotBlank(message = "title 字典内容不能为空", groups = ValidGroups.DictReqContentValid.class)
@NotBlank(message = "title {item.not_empty}", groups = ValidGroups.DictReqContentValid.class)
private String title;
@NotNull(message = "value 字典内容值不能为 NULL", groups = ValidGroups.DictReqContentValid.class)
@NotNull(message = "value {item.not_null}", groups = ValidGroups.DictReqContentValid.class)
private Integer value;
private Integer sorted;
private String cssClass;

View File

@ -25,22 +25,22 @@ import java.util.List;
@AllArgsConstructor
public class ResourceInfo {
@Schema(description = "资源路径")
@NotNull(message = "path 资源 URL 不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
@NotBlank(message = "path 资源 URL 不能为空字符串", groups = ValidGroups.ResourceInfoValid.class)
@NotNull(message = "path {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
@NotBlank(message = "path {item.not_empty}", groups = ValidGroups.ResourceInfoValid.class)
private String path;
@Schema(description = "资源名称")
@NotNull(message = "name 资源名称不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
@NotBlank(message = "name 资源名称不能为空字符串", groups = ValidGroups.ResourceInfoValid.class)
@NotNull(message = "name {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
@NotBlank(message = "name {item.not_empty}", groups = ValidGroups.ResourceInfoValid.class)
private String name;
@Schema(description = "资源类型名称")
@NotNull(message = "resTypeId 资源名称不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
@NotNull(message = "resTypeId {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
private Integer resTypeId;
@Schema(description = "HTTP 方法")
@NotNull(message = "HttpMethod 方法名称不能为 NULL", groups = ValidGroups.ResourceInfoValid.class)
@Size(min = 1, max = 8, message = "HttpMethod HTTP 方法名称不能为空", groups = ValidGroups.ResourceInfoValid.class)
@NotNull(message = "HttpMethod {item.not_null}", groups = ValidGroups.ResourceInfoValid.class)
@Size(min = 1, max = 8, message = "HttpMethod HTTP {array.value_range}", groups = ValidGroups.ResourceInfoValid.class)
@ValidHttpMethod(groups = ValidGroups.ResourceInfoValid.class)
private List<String> httpMethod;
}

View File

@ -1,5 +1,7 @@
package com.cf.cs.protocol.validation.valids.impl;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.cf.cs.protocol.validation.valids.ValidHttpMethod;
import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
@ -27,7 +29,8 @@ public class ValidHttpMethodImpl implements ConstraintValidator<ValidHttpMethod,
if (RequestMethod.resolve(k.toUpperCase()) == null) {
errMsg.append("[")
.append(k)
.append("]: 不是合法的 HTTP 请求方法");
.append("]: ")
.append(MessageUtil.get("http.request_invalid", ApiContextUtils.getLanguare()));
}
});

View File

@ -2,6 +2,8 @@ package com.cf.cs.protocol.validation.valids.impl;
import com.cf.cs.base.common.ConstValue;
import com.cf.cs.base.misc.ApiContextUtils;
import com.cf.cs.base.misc.MessageUtil;
import com.cf.cs.protocol.config.ProtocolConfigure;
import com.cf.cs.protocol.validation.valids.ValidProtocolTimestamp;
import jakarta.validation.ConstraintValidator;
@ -35,15 +37,16 @@ public class ValidProtocolTimestampImpl implements ConstraintValidator<ValidProt
if (timeStamp > System.currentTimeMillis()) {
String errMsg = String.format("请求时间[%s] 大于当前服务器时间 [%s]", date, current);
String errMsg = MessageUtil.get("timeout.current.format", new String[] {date, current}, ApiContextUtils.getLanguare());
//禁用默认的message的值
constraintValidatorContext.disableDefaultConstraintViolation();
//重新添加错误提示语句
constraintValidatorContext.buildConstraintViolationWithTemplate(errMsg).addConstraintViolation();
return false;
} else if (System.currentTimeMillis() - timeStamp > ProtocolConfigure.TIMEOUT_OF_SECONDS * ConstValue.MS_OF_SECONDS) {
String errMsg = String.format("请求时间[%s] 延时超过当前服务器时间[%s] 允许范围 %d(S)", date, current,
ProtocolConfigure.TIMEOUT_OF_SECONDS);
String errMsg = MessageUtil.get("timeout.current.format",
new String[] {date, current, String.valueOf(ProtocolConfigure.TIMEOUT_OF_SECONDS)},
ApiContextUtils.getLanguare());
//禁用默认的message的值
constraintValidatorContext.disableDefaultConstraintViolation();
//重新添加错误提示语句