Could not instantiate bean class [java.util.Date]: Constructor threw exception; nested exception is java.lang.IllegalArgumentException
Spring MVC 时间参数没有转化的原因
参考 https://blog.csdn.net/wwrzyy/article/details/79690601
console报错是这样,但是页面报错400,请求错误,但是还会报一些奇怪的错误令人费解:
Uncaught SyntaxError: Unexpected token <很具有迷惑性。
这里其实是springmvc在进行对象封装的时候对时间字段需要我们自己在controller层进行格式化,下面将这段代码添加到controller层就好
/**
* 数据初始化绑定:SpringMVC中,数据从前台过来会将字符串转换为日期对象
* @param binder
*/
@InitBinder
public void initBinder(WebDataBinder binder) {
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");//格式根据个人需求进行设定
dateFormat.setLenient(false);
binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true)); //true:允许输入空值,日期可以为空,false:不能为空值
}