數組對象裏面又嵌套了java bean對象java
$.post()
方法發現上傳不成功,後來發現須要自定義請求類型
contentType
,後來改成使用$.ajax()方法發送請求.
$.ajax({
// 請求路徑
url: `${contextPath}report/user/batchDelete`,
// 先將數據壓縮成字符串,發送到後臺
data: JSON.stringify(data),
// 文件類型爲json格式,關鍵是要重寫這一步
contentType: 'application/json; charset=UTF-8',
// post請求
method: 'POST',
// 請求成功後調用的方法
success: function (res) {
res = JSON.parse(res);
if (res.status === 200) {
// obj.del(); //刪除對應行(tr)的DOM結構,並更新緩存
table.reload('reportList', {
page: obj.config.page.curr,
where: {
recordTitle: searchWord
}
})
layer.msg('批量刪除數據成功');
} else if (res.status === 500) {
// 失敗的狀況
layer.msg('批量刪除數據失敗');
}
}
})
複製代碼
後臺spring mvc代碼ajax
@RequestMapping("/batchDelete")
@ResponseBody
public JSONObject batchDelete(@RequestBody List<Report> reports) {
// 使用@RequestBody來表示接收的是一個對象
System.out.println(reports);
JSONObject results = new JSONObject();
results.put(CommonVariable.RESPONSE_STATUS_NAME, reportService.deleteRecordBatchByRecordId(reports) >= reports.size() ? CommonVariable.RESPONSE_STATUS_SUCCESS : CommonVariable.RESPONSE_STATUS_ERROR);
return results;
}
複製代碼