1. 程式人生 > >The request sent by the client was syntactically incorrect解決

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));
    }

問題解決

小結:一定要注意引數名字是否一致或者提交的引數格式是否沒滿足資料庫的要求,不然就會報標題的錯誤,我這裡是比較低階的日期轉換錯誤。