The request sent by the client was syntactically incorrect解决

在请求页面时,浏览器报错:

 The request sent by the client was syntactically incorrect的字面意思是:客户端发送的请求在语法上是错误的。

这个提示不够详细,看了一下后台,后台给的部分提示如下:

Failed to convert from type java.lang.String to type java.util.Date for value '2018-10-02'; nested exception is java.lang.IllegalArgumentException]

说明我页面提交的日期数据的格式是错误的,数据库识别不了提交的 "2018-10-02';

解决方法:

调用如下方法:

public void initBinder(WebDataBinder binder) {
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
        dateFormat.setLenient(true);
        binder.registerCustomEditor(Date.class, new CustomDateEditor(dateFormat, true));
    }

问题解决

小结:一定要注意参数名字是否一致或者提交的参数格式是否没满足数据库的要求,不然就会报标题的错误,我这里是比较低级的日期转换错误。

猜你喜欢

转载自blog.csdn.net/zhou_438/article/details/83476190