首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Hibernate Validator和Joda DateTime Validator

Hibernate Validator和Joda DateTime Validator
EN

Stack Overflow用户
提问于 2014-12-05 02:51:06
回答 2查看 1.5K关注 0票数 2

我有一个用户模型类,其中包含一个Joda DateTime字段,并遵循以下验证规则:

代码语言:javascript
复制
@NotEmpty
@DateTimeFormat(pattern="dd/MM/yyyy")
@Past
private DateTime dob;

一旦我提交了我的登记表,我就会收到以下错误:

代码语言:javascript
复制
No validator could be found for type: org.joda.time.DateTime.

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

EN

回答 2

Stack Overflow用户

发布于 2014-12-05 03:44:13

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

票数 0
EN

Stack Overflow用户

发布于 2015-11-02 15:39:26

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

@Past只适用于(非Joda) DateCalendar。我不知道有一个库为Joda类型提供了Java验证器。

FYI,@Past的Javadoc声明它支持哪种类型:

代码语言:javascript
复制
/**
 * 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
 */
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27307961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档