数组对象里面又嵌套了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;
}
复制代码