HibernateValidators
public final class HibernateValidators {
private static final Validator VALIDATOR;
private HibernateValidators() {
}
static {
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
VALIDATOR = factory.getValidator();
}
public static <T> Set<ConstraintViolation<T>> validate(T object, Class<?>... groups) {
return VALIDATOR.validate(object, groups);
}
/**
* @throws IllegalArgumentException 当校验有错误的时候抛出异常
*/
public static <T> void throwsIfInvalid(T object, Class<?>... groups) {
final Set<ConstraintViolation<T>> constraintViolations = validate(object, groups);
if (!constraintViolations.isEmpty()) {
final ImmutableMap.Builder<String, String> errorBuilder = ImmutableMap.builder();
for (ConstraintViolation<T> violation : constraintViolations) {
errorBuilder.put(violation.getPropertyPath().toString(), violation.getMessage());
}
throw new IllegalArgumentException(errorBuilder.build().toString());
}
}
}
HibernateValidators的更多相关文章
- 【转载】springMVC表单校验+全注解
在这篇文章中,我们将学习如何使用Spring表单标签, 表单验证使用 JSR303 的验证注解,hibernate-validators,提供了使用MessageSource和访问静态资源(如CSS, ...
- spring mvc:练习:表单验证(javaConfig配置和注解)
使用Spring表单标签, 表单验证使用 JSR303 的验证注解,hibernate-validators,提供了使用MessageSource和访问静态资源(如CSS,JavaScript,图片) ...
- Spring4 MVC表单验证
在这篇文章中,我们将学习如何使用Spring表单标签, 表单验证使用 JSR303 的验证注解,hibernate-validators,提供了使用MessageSource和访问静态资源(如CSS, ...
随机推荐
- 最完整的dos命令字典,IIS服务命令,FTP命令
https://www.cnblogs.com/accumulater/p/10670051.html(优秀博文) 一.最完整的dos命令字典net use ipipc$ " " ...
- 昨天开始使用lr controller 已停止工作问题
其实看到这个,只能看日志 看到日志也是无能为力 然后只能尝试修复,但是无法解决,最后通过重装系统,问题解决
- Scala数组| 集合
arrays :+ 5尾部 头部5 +: arrays TODO 声明不可变数组,不能删; 默认情况下,scala中集合的声明全都是不可变的 val arrays: Array[Int] = Ar ...
- Windows上为Apache配置HTTPS
Windows上为Apache配置HTTPS 转 https://www.cnblogs.com/tianzijiaozi/p/7582671.html 1. 安装OpenSSL: Windo ...
- eclipse怎么对项目重命名,eclipse怎么重命名类
eclipse怎么对项目重命名,eclipse怎么重命名类
- 利用kibana插件对Elasticsearch进行批量操作
#############批量获取################# #获取所有数据 GET _mget { "docs": [ {"_index":" ...
- Win10 清理自带APP
如果想一次性把它们全都删掉,请输入: Get-AppxPackage -AllUsers | Remove-AppxPackage 但是如果你先建一个账户,以上应用就会再次全部出现,不想这样的话可以输 ...
- NEO智能合约开发(一)不可能完成的任务
悬赏任务 兹有如下合约 public static object Main(string method, object[] args) { if (Runtime.Trigger == Trigger ...
- git 中文文档 及测试命令
git 使用官方中文文档 https://git-scm.com/book/zh/v2/ 或者你在github上只填写一个仓库名称点击创建后会跳转一个页面给出参考命令如下 echo "# w ...
- Hibernate 映射多对多关联关系
映射多对多,需要建立一张中间表 一共三张表,一个是 Category,一个是 Item,还有一个是 Categories_Items Categories_Items 作为中间表,其包含两个列,分别对 ...