问题遇到的现象和发生背景
问题相关代码,请勿粘贴截图
这是之前的代码,能够正常运行,但是现在回过头来看我也有点搞不懂为什么这个Mid能传到后端,是因为在这个ajax里的data后端接收到根据Mid,直接传到参数列表里吗
function deleteMedicine(Mid) {
if (sure() == false)
return;
$.ajax({
url: 'deleteMedicine',
type: "get",
data: {"Mid": Mid},
dataType: "json",
success: function (json) {
if (json.state == 200) {
alert("删除成功!")
showMedicineList(json)
} else {
alert("删除失败!")
}
},
error: function (json) {
alert("删除失败")
}
})
}
```java
@GetMapping("deleteMedicine")
@ResponseBody
public JsonResult<PageInfo> deleteMedicine(int Mid){
medicineService.deleteMedicineByMid(Mid);
PageHelper.startPage(1,5);
List<Medicine> data1 = medicineService.findMedicineList();
PageInfo data = new PageInfo(data1);
return new JsonResult<>(200,data);
}
```javascript
function deleteMedicine(Mid) {
if (sure() == false)
return;
$.ajax({
url: 'deleteMedicine/#{Mid}',
type: "put",
data: {"Mid": Mid},
dataType: "json",
success: function (json) {
if (json.state == 200) {
alert("删除成功!")
showMedicineList(json)
} else {
alert("删除失败!")
}
},
error: function (json) {
alert("删除失败")
}
})
}
```java
@PutMapping("deleteMedicine/{Mid}")
@ResponseBody
public JsonResult<PageInfo> deleteMedicine(@PathVariable("Mid") int Mid){
medicineService.deleteMedicineByMid(Mid);
PageHelper.startPage(1,5);
List<Medicine> data1 = medicineService.findMedicineList();
PageInfo data = new PageInfo(data1);
return new JsonResult<>(200,data);
}
这样写就报405,有点乱了
我把上面的get改成put,因为我的删除只是更新标记,就会报下面500的错,说Mid不能为null就是后端没有接收到,那我应该怎么让后端接收到