hibernate的校验
2024-10-21 16:40:00
//不使用@valid进行校验
Set<ConstraintViolation<CommonValidator>> validates = validator.validateValue(CommonValidator.class, "name", null);
for (ConstraintViolation<CommonValidator> validate : validates) {
ConstraintViolationImpl validate2= (ConstraintViolationImpl)validate;
Annotation annotation = validate2.getConstraintDescriptor().getAnnotation();
Class<? extends Annotation> aClass = annotation.annotationType();
String messageTemplate = validate2.getConstraintDescriptor().getMessageTemplate();
System.out.println(validate.getMessage());
if (aClass.equals(NotEmpty.class)){
System.out.println("messageTemplate:"+messageTemplate);
throw new RuntimeException("not empty异常了");
}
}
System.out.println("成功");
最新文章
- Java基础知识系列——目录操作
- iOS Block 内存管理的探讨
- 在Eclipse中手动安装pydev插件,eclipse开发python环境配置
- PHP中float变量转换为int时,结果有误的问题!
- MyBatis知多少(20)MyBatis读取操作
- 中间件、MetaQ入门学习
- ftime() 系统时间
- 【BZOJ】【1324】王者之剑
- SVN服务器使用(二)
- android学习—— LayoutInflater的使用
- Arrays和Collections 对于sort的不同实现原理
- SQL Server中的变更捕获技术--简单部署
- A customized combobox with JQuery
- struts2 在 Action 或 Interceptor 中获取 web.xml 中配置的 <;context-param>; 参数 (这是我的第一篇博文,哈哈。)
- jQuery 练习:tab 切换
- mysql:general_log 日志、数据库线程查询、数据库慢查询
- js 自定义类Android吐司提示框
- .NET Core微服务之路:利用DotNetty实现一个简单的通信过程
- video自动禁止全屏
- Binomial Coefficient(二项式系数)