一、問題描述:
springboot框架,前台通過ajax像后台controller傳遞參數。
前台代碼:
$.ajax({ type: "POST",//方法類型 contentType:'application/json', dataType: "json",//預期服務器返回的數據類型 url: "http://localhost:8080/saveRBD",//url data: JSON.stringify(list),//list是鏈表結構 success: function (data) { console.log("成功"); }, error: function (result) { console.log("失敗"); }
});
后台代碼:
//添加數據 @RequestMapping("/add") @ResponseBody public int addList(@RequestBody LinkedList list){ int result = rbdService.addRBD(list); return result; }
報錯:
Can not deserialize instance of java.util.ArrayList out of START_OBJECT token
二、分析原因
客戶端返回類型與接收類型不一致。
三、解決
轉換成簡單的數據類型或者自己封裝成對象來傳遞並且接收。