且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring MVC HTTP状态400-错误的请求

更新时间:2022-06-19 07:04:06

提交HTTP POST时必须绑定Date. Spring不知道这是Date,而是将其视为String.

You must bind the Date when you submit a HTTP POST. Spring does not know that this is a Date, it sees it as a String.

添加此内容:

@InitBinder
public void initBinder(WebDataBinder binder) {
    SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy");
    sdf.setLenient(true);
    binder.registerCustomEditor(Date.class, new CustomDateEditor(sdf, true));
}

致您的控制器.