Hibernate Validator 中文操作指南

Preface

验证数据是一项常见任务,贯穿所有应用程序层,从表示层到持久层。通常在每一层实施相同的验证逻辑,这既耗时又容易出错。为了避免重复这些验证,开发人员通常将验证逻辑直接捆绑到领域模型中,用实际上是类本身的元数据的验证代码弄乱领域类。

Validating data is a common task that occurs throughout all application layers, from the presentation to the persistence layer. Often the same validation logic is implemented in each layer which is time consuming and error-prone. To avoid duplication of these validations, developers often bundle validation logic directly into the domain model, cluttering domain classes with validation code which is really metadata about the class itself.

application layers

Jakarta Bean 验证 3.0 为实体和方法验证定义了一个元数据模型和 API。默认元数据源是注释,能够通过使用 XML 来覆盖和扩展元数据。API 并不绑定到任何特定应用程序层或编程模型。它明确不绑定到 Web 或持久层,且可用于服务器端应用程序编程和富客户端 Swing 应用程序开发人员。

Jakarta Bean Validation 3.0 defines a metadata model and API for entity and method validation. The default metadata source are annotations, with the ability to override and extend the meta-data through the use of XML. The API is not tied to a specific application tier nor programming model. It is specifically not tied to either web or persistence tier, and is available for both server-side application programming, as well as rich client Swing application developers.

application layers2

Hibernate 验证器是 Jakarta Bean 验证器的参考实现。实现本身以及 Jakarta Bean 验证器 API 和 TCK 均在 Apache Software License 2.0下提供和分发。

Hibernate Validator is the reference implementation of Jakarta Bean Validation. The implementation itself as well as the Jakarta Bean Validation API and TCK are all provided and distributed under the Apache Software License 2.0.

Hibernate 验证器 8 和 Jakarta Bean 验证 3.0 需要 Java 11 或更高版本。

Hibernate Validator 8 and Jakarta Bean Validation 3.0 require Java 11 or later.