问题描述:
使用前端表单提交包含时间格式的数据时,springboot可能出现无法解析特定的时间(日期格式)的问题,就是2018-05-15 和2019/05/15之间无法转换等
解决办法
在需要接收相应表单的controller中添加如下方法即可
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
}