Ajax中Delete请求参数 后台无法获取的解决方法(Restful风格)

时间:2021-08-15 09:06:00

方法一:

在ajax中写入data来传参时,直接把参数拼接到url后面

例如:

 $.ajax({
url: '/cyberspace/vrv/event/delete/1002?startTime="2018-03-07 11:39:27"&userId=123456',
type: "delete",
contentType: "application/json",
dataType: "json",
success: function (msg) {
console.log(msg);
}
});
@DeleteMapping("/vrv/event/delete/{eventId}")

方法二:

$.ajax({
url: '/cyberspace/vrv/event/delete/1002',
type: 'POST',
data: {
startTime: "2018-03-07 11:39:27",
userId: 123456,
_method: 'DELETE'
},
success: function (msg) {
console.log(msg);
}
});
@RequestMapping(value = "/vrv/event/delete/{eventId}", method = RequestMethod.DELETE)