Hibernate验证:如何处理翻转? (28/14/2009变得28/2/2010)
-
25-09-2019 - |
题
我使用的是Hibernate验证来验证我的形式。 我有“问题”的14月9日成为第二个月在明年。 (刚连接例子的场景)。
我想知道我怎么能防止预设的转换,反而显示自定义错误消息它。
有谁还知道,如果我的自定义编辑器抛出IllegalArgumentException我如何能够显示一个approperiate消息?
@InitBinder
public void initBinder(WebDataBinder binder) {
CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("dd/MM/yyyy"), true);
binder.registerCustomEditor(Date.class, editor);
}
我registred一个customEditor因为弹簧的portlet-MVC有与结合
的一些问题解决方案
此行为由DateFormat.setLenient()
控制,并没有任何关系的验证(有setLentient(false)
它在结合阶段产生一个类型不匹配的错误):
DateFormat df = new SimpleDateFormat("dd/MM/yyyy");
df.setLenient(false);
CustomDateEditor editor = new CustomDateEditor(df, true);
binder.registerCustomEditor(Date.class, editor);
不隶属于 StackOverflow