【发布时间】:2019-08-16 07:45:03
【问题描述】:
我尝试过使用@QueryParam、@PathVariable 和@RequestParam,但我的控制器没有从AJAX 调用中获取数据请求。我的其他方法也有同样的方法。只有 DELETE 请求不起作用,我得到空值。我已经提到了这个Ajax delete method in spring boot,但它对我不起作用。
//AJAX DELETE
var id = {"id":$("#deleteUserIdInput").val()};
$("#deleteUserModal").modal("hide");
$.ajax({
url : "http://localhost:3000/delete-user",
datatype : "json",
method : "DELETE",
data : id,
contentType : "application/json",
error:function(data){
console.log(data.entity);
}
}).done(function(data) {
console.log(data.entity)
}
);
//Controller
//http://localhost:3000/delete-user
@RequestMapping(value="/delete-user", method = RequestMethod.DELETE)
@ResponseBody
public Integer deleteUser(@QueryParam("id") Integer id){
return id;
}
我在传递给请求之前测试数据,它不为空。我希望返回传递给请求的数据,例如 1,但我得到了未定义。
【问题讨论】:
标签: java ajax spring-boot spring-boot-maven-plugin