一、前端代码
var ids = [];//定义一个数组
$(selectRow).each(function(i, row){
ids[i] = row.id;
});
$.messager.confirm("消息提醒", "将删除与课程相关的所有数据,确认继续?", function(r){
if(r){
$.ajax({
type: "post",
dataType:'json',
url: "/course/deleteCourse",
contentType: 'application/json',//这个要有,后台用@requestBody接收
data: JSON.stringify(ids),//转换成json格式
二、后台代码
@PostMapping("/deleteCourse")
@ResponseBody
//注意:集合的参数名必须和前台一致,否则无法接收到
public Object deleteCourse(@RequestBody List<Integer> ids,HttpServletResponse response) {
int count = courseService.deleteCourseById(ids);
System.out.println(count);
String msg = "error";
if (count>0) {
msg= "success";
}
return msg;
}