我有一个用户模型类,其中包含一个Joda DateTime字段,并遵循以下验证规则:
@NotEmpty
@DateTimeFormat(pattern="dd/MM/yyyy")
@Past
private DateTime dob;一旦我提交了我的登记表,我就会收到以下错误:
No validator could be found for type: org.joda.time.DateTime.如何将验证器添加到此字段?
发布于 2014-12-05 03:44:13
使用@NotNull而不是@NotEmpty来解决问题。
发布于 2015-11-02 15:39:26
您必须编写自己的验证器,以便与Joda的DateTime一起使用。
@Past只适用于(非Joda) Date和Calendar。我不知道有一个库为Joda类型提供了Java验证器。
FYI,@Past的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
*/https://stackoverflow.com/questions/27307961
复制相似问题