春季验证与休眠验证 [英] Spring Validation vs Hibernate Validation

查看:103
本文介绍了春季验证与休眠验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在对两者感到困惑.我知道Hibernate Validator 6是Bean Validation 2.0规范的参考实现.它支持分组, 错误消息的国际化,自定义方法验证等. 问题是Spring 5是否支持这些功能,还是我只剩下Hibernate Validator 6?

I am confused between the two now. I know Hibernate Validator 6 is the reference implementation for Bean Validation 2.0 specs. It supports Grouping, Internationalization of error messages, Custom Method Validations etc. Question is does Spring 5 support these features or am I only left with Hibernate Validator 6?

为什么我应该在我的Spring Boot项目中使用Hibernate Validator而不是提供的Spring Validation?我的公司需要使用任何第三方库的理由.

Why should I used Hibernate Validator along with my Spring Boot project instead of the provided Spring Validation? My company needs a justification to use any third party library.

所有在线参考示例都建议使用Hibernate Validator,而在Spring验证中发现的内容不多,请告知或指向其他链接.

All the reference example online suggest to use Hibernate Validator and nothing much found on Spring validation, please advise or point to other links.

推荐答案

根据

使用Bean验证时,只有一个javax.validation.Validator实例 通常验证所有声明验证的模型对象 约束.使用Spring配置这样的JSR-303支持的验证器 MVC,只需添加一个Bean验证提供程序,例如Hibernate 验证器,到您的类路径

With Bean Validation, a single javax.validation.Validator instance typically validates all model objects that declare validation constraints. To configure such a JSR-303 backed Validator with Spring MVC, simply add a Bean Validation provider, such as Hibernate Validator, to your classpath

您可以通过创建具有spring-boot-starter-web依赖项的示例spring-boot项目来验证这一点.实际上,它会将hibernate-validator依赖项添加到您的类路径中

you can verify that by creating sample spring-boot project with spring-boot-starter-web dependency. It actually adds hibernate-validator dependency into your classpath

在春季教程中,有几个指向jsr-303的链接:

Here are couple of links to jsr-303 in spring tutorials:

  1. https://howtodoinjava.com/spring/spring-mvc/spring-bean-validation-example-with-jsr-303-annotations/

https://www.mkyong.com/spring-mvc/spring-3-mvc-and-jsr303-valid-example/

这篇关于春季验证与休眠验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆