@Future 的实现在哪里定义? [英] Where is implementation of @Future defined?

查看:98
本文介绍了@Future 的实现在哪里定义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Java 持久化 &Hibernate 可以轻松地向实体添加属性级约束.

@Entity@Table(name = "party")公共类派对实体{@未来公共日期时间开始;}

javax.validation.constraint.Future 注释是在没有具体实现的情况下定义的.

@Target({ 方法, 字段, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })@保留(运行时间)@记录@Constraint(validatedBy = {})公共@interface 未来{//...}

实际验证在哪里实施?如何扩展以允许管理员覆盖?

虽然这里没有显示,但我已经将组用于此约束的其他目的.

解决方案

hibernate-validator 提供的许多验证器的实现:http://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/validator-usingvalidator.html#validator-defineconstraints-builtin

如果您使用 Maven,只需在 pom.xml 文件中添加以下依赖项:

<依赖><groupId>org.hibernate</groupId><artifactId>hibernate-validator</artifactId><version>5.0.0.Alpha1</version></依赖>

<块引用>

如何扩展以允许管理员覆盖?

最简单的方法是写你自己的.

Java persistence & hibernate make it easy to add property-level constraints to entities.

@Entity
@Table(name = "party")
public class PartyEntity {
    @Future
    public DateTime start;
}

The javax.validation.constraint.Future annotation is defined without a specific implementation.

@Target({ METHOD, FIELD, ANNOTATION_TYPE, CONSTRUCTOR, PARAMETER })
@Retention(RUNTIME)
@Documented
@Constraint(validatedBy = {})
public @interface Future {
    // ...
}

Where is actual validation implemented? How can this be extended to allow an administrator override?

Though not shown here, I am already using groups for another purpose on this constraint.

解决方案

Implementations for many validators supplied by hibernate-validator: http://docs.jboss.org/hibernate/validator/5.0/reference/en-US/html/validator-usingvalidator.html#validator-defineconstraints-builtin

If you are using Maven just add following dependency to pom.xml file:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-validator</artifactId>
    <version>5.0.0.Alpha1</version>
</dependency>

How can this be extended to allow an administrator override?

The simplest way is to write your own instead.

这篇关于@Future 的实现在哪里定义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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