当我尝试输入日期格式 40/40/2017 时,spring webflow 将其转换为快速时间并将其转换为有效日期。这可以避免 validator 抛出任何错误。有什么方法可以使其无效而不将变量转换为字符串吗?
最佳答案
由于Spring MVC
中有多种方法可以解决这些问题,例如使用initBinder
。首先将此日期值传递给initBinder,以便它会抛出错误(在 validator 的验证时间)。
试试这个可能会有帮助
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy");
binder.registerCustomEditor(Date.class, new
CustomDateEditor(dateFormat,true));
}
关于java - Spring Webflow 中允许的月份和日期无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46429656/