我正在使用自定义编辑器将String转换为日期。我的代码在下面提到
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, false));
}
Run Code Online (Sandbox Code Playgroud)
当我在“ yyyy-MM-dd”中输入日期时,将其插入。
但是当我输入空白时会引发异常
嵌套异常为java.lang.IllegalArgumentException:无法解析日期:无法解析的日期:“”
我无法验证相同的结果。
如果我给出其他格式,它也无法解析。