【问题标题】:Invalid month and date allowed in spring webflowspring webflow中允许的无效月份和日期
【发布时间】:2019-01-08 00:17:38
【问题描述】:

当我尝试输入日期格式 40/40/2017 时,spring webflow 将其转换为快速时间并将其转换为有效日期。这避免了验证器抛出的任何错误。有什么方法可以在不将变量转换为字符串的情况下使其无效?

【问题讨论】:

标签: java spring-webflow


【解决方案1】:

Spring MVC 中有几种方法可以解决这些问题,例如使用 initBinder。首先将此 Date 值传递给 initBinder,以便验证器会抛出错误(在验证时)。
试试这个可能会有帮助

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
    binder.registerCustomEditor(Date.class, new 
                                       CustomDateEditor(dateFormat,true));
}

【讨论】:

  • 您可能希望在您的活页夹中 dateFormat.setLenient(false),以便像 month=40 这样的值被接受。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-08-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多