Spring Hibernate验证程序和Joda日期时间验证程序

Spring Hibernate验证程序和Joda日期时间验证程序,spring,hibernate,jodatime,thymeleaf,Spring,Hibernate,Jodatime,Thymeleaf,我有一个用户模型类,带有一个Joda DateTime字段和以下验证规则: @NotEmpty @DateTimeFormat(pattern="dd/MM/yyyy") @Past private DateTime dob; 一旦我提交了注册表,就会出现以下错误: No validator could be found for type: org.joda.time.DateTime. 如何将验证器添加到此字段?使用@NotNull而不是@NotEmpty来解决此问题。您必须编写自己的验证

我有一个用户模型类,带有一个Joda DateTime字段和以下验证规则:

@NotEmpty
@DateTimeFormat(pattern="dd/MM/yyyy")
@Past
private DateTime dob;
一旦我提交了注册表,就会出现以下错误:

No validator could be found for type: org.joda.time.DateTime.

如何将验证器添加到此字段?

使用
@NotNull
而不是
@NotEmpty
来解决此问题。

您必须编写自己的验证器,以便与Joda的
DateTime
一起使用

@pass
仅适用于(非Joda)
日期
日历
。我不知道有哪个库为Joda类型提供JavaBean验证程序

仅供参考,
@pass
的Javadoc说明了它支持的类型:

/**
 * The annotated element must be a date in the past.
 * Now is defined as the current time according to the virtual machine.
 * <p/>
 * The calendar used if the compared type is of type {@code Calendar}
 * is the calendar based on the current timezone and the current locale.
 * <p/>
 * Supported types are:
 * <ul>
 *     <li>{@code java.util.Date}</li>
 *     <li>{@code java.util.Calendar}</li>
 * </ul>
 * <p/>
 * {@code null} elements are considered valid.
 *
 * @author Emmanuel Bernard
 */
/**
*带注释的元素必须是过去的日期。
*Now根据虚拟机定义为当前时间。
*

*如果比较的类型为{@code calendar}类型,则使用的日历 *是基于当前时区和当前区域设置的日历。 *

*支持的类型包括: *

    *
  • {@code java.util.Date}
  • *
  • {@code java.util.Calendar}
  • *
*

*{@code null}元素被认为是有效的。 * *@作者伊曼纽尔·伯纳德 */


愚蠢的问题,但你有“import org.joda.time.format.DateTimeFormat;”在那门课的某个地方吗?我正在使用org.springframework.format.annotation.DateTimeFormat将它用于我所听的一个注释。g.joda.time.format.DateTimeFormat不是注释。你是对的,我意识到我读错了。让我再试一试。你是如何进行验证的?你能展示你的方法和验证的代码吗。