【发布时间】:2019-01-08 00:17:38
【问题描述】:
当我尝试输入日期格式 40/40/2017 时,spring webflow 将其转换为快速时间并将其转换为有效日期。这避免了验证器抛出的任何错误。有什么方法可以在不将变量转换为字符串的情况下使其无效?
【问题讨论】:
-
请参阅此链接以获取有关此问题的更多帮助:stackoverflow.com/questions/14156651/…
标签: java spring-webflow
当我尝试输入日期格式 40/40/2017 时,spring webflow 将其转换为快速时间并将其转换为有效日期。这避免了验证器抛出的任何错误。有什么方法可以在不将变量转换为字符串的情况下使其无效?
【问题讨论】:
标签: java spring-webflow
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 这样的值不被接受。