Java 是否有可用的 JSR-303(bean 验证)的实现?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1384968/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there an implementation of JSR-303 (bean validation) available?
提问by flybywire
I know there are non-standard frameworks such as commons-validator, and hibernate validator.
我知道有非标准框架,例如 commons-validator 和 hibernate validator。
I wanted to know if someone knows an implementation of the official standard.
我想知道是否有人知道官方标准的实现。
采纳答案by skaffman
Hibernate Validator is the reference implementationof JSR-303
Hibernate Validator 是JSR-303的参考实现
回答by Martin K.
回答by bashflyng
There are 2 compliant implementations now:
现在有 2 个兼容的实现:
- Apache Bean Validation(formerly agimatec)
- Hibernate Validator
- Apache Bean 验证(以前称为 agimatec)
- 休眠验证器
You can access a benchmark and a quick description of both here: http://carinae.net/2010/06/benchmarking-hibernate-validator-and-apache-beanvalidation-the-two-jsr-303-implementations/
您可以在此处访问基准测试和两者的快速描述:http: //carinae.net/2010/06/benchmarking-hibernate-validator-and-apache-beanvalidation-the-two-jsr-303-implementations/
回答by schnitz
回答by VHS
Spring Framework became JSR303 compliant from version 3 onward I think.
我认为 Spring Framework 从第 3 版开始就符合 JSR303。
Spring Framework 4.0 supports Bean Validation 1.0 (JSR-303) and Bean Validation 1.1 (JSR-349) in terms of setup support, also adapting it to Spring's Validator interface.
Spring Framework 4.0 在设置支持方面支持 Bean Validation 1.0 (JSR-303) 和 Bean Validation 1.1 (JSR-349),也使其适应 Spring 的 Validator 接口。
回答by Mikhail Dyakonov
As for summer 2018, there are three specifications that supersed each other:
至于2018年夏季,三个规格相互取代:
- JSR 380 (Bean Validation 2.0)
- JSR 349 (Bean Validation 1.1)
- JSR 303 (Bean Validation 1.0)
- JSR 380(Bean 验证 2.0)
- JSR 349(Bean 验证 1.1)
- JSR 303(Bean 验证 1.0)
You can consult the official sitefor more details.
您可以访问官方网站了解更多详情。
Hibernate Validator 6.10is a reference implementation of the newest one (380). It has a great documentationI'd recommend to take a look at (however it's quite big stuff).
Hibernate Validator 6.10是最新版本 (380) 的参考实现。它有一个很棒的文档,我建议您查看一下(但是它是相当大的内容)。
CUBA platform docscould give you a much shorter grasp of the topic if you need just a fast intro. CUBA framework is based on Spring and EclipseLink, so the things you've learned could be used on regular Spring+Hibernate projects as well :)
如果您只需要快速介绍,CUBA 平台文档可以让您更快速地掌握该主题。CUBA 框架基于 Spring 和 EclipseLink,所以你学到的东西也可以用在常规的 Spring+Hibernate 项目中 :)
The JSR 349 is supported by older versions of Hibernate Validator and by Apache BVal, both of them are "official".
JSR 349 由旧版本的 Hibernate Validator 和Apache BVal支持,它们都是“官方的”。
From ORMs other than Hibernate, EclipseLinksupports JSR 349 and can use Validator interface provided by HV.
从 Hibernate 以外的 ORM 中,EclipseLink支持 JSR 349 并且可以使用 HV 提供的 Validator 接口。
If it's possible, I would recommend to not use the older version (JSR 303) but switch to 349 or 380 specs. They are quite more mature and rich.
如果可能,我建议不要使用旧版本 (JSR 303),而是切换到 349 或 380 规范。他们更加成熟和富有。
Bean Validation could be used in the project even there is no ORM in it, for example you can use it your Java 2SE or Android apps (see this article), however, this is not the approach Bean Validation was designed for as a primary thing. Although it's possible to use these validators (HV and BVal) just by itself (you'd have to instantiate and call Validator
and ExecutableValidator
manually), they will really shine working together with frameworks like Hibernate, Spring or CUBA
即使项目中没有 ORM,也可以在项目中使用 Bean 验证,例如,您可以在 Java 2SE 或 Android 应用程序中使用它(请参阅本文),但是,这不是 Bean 验证设计的主要方法. 尽管可以单独使用这些验证器(HV 和 BVal)(您必须实例化、调用Validator
和ExecutableValidator
手动),但它们与 Hibernate、Spring 或CUBA等框架一起工作时确实会发光