$.ajax({ type: 'delete', method: 'delete', url: '/BookShopSystem_war/deleteBookById/' + data.bookId, data: {"bookId": data.bookId}, dataType: 'json', success: function (result) { if (result.code == 0) { layer.msg(result.msg); table.reload("table") } else { layer.msg(result.msg) } } })@DeleteMapping("/deleteBookById/{bookId}") @ResponseBody public Map<String, Object> deleteBookById(@PathVariable("bookId") Integer bookId) { int deleteResult = adminService.deleteBookById(bookId); if (!(deleteResult == 1)) { System.out.println("删除失败"); } Map<String, Object> result = new HashMap<>(); result.put("code", 0); result.put("msg", "删除成功"); return result; }如果调用该接口还需要一个参数userId,那么应该如何修改
时间: 2024-02-10 20:09:40 浏览: 85
如果调用该接口需要传递userId参数,可以将该参数作为请求参数传递给后台,在Controller中使用@RequestParam注解获取该参数,例如:
前端代码:
```javascript
$.ajax({
type: 'delete',
method: 'delete',
url: '/BookShopSystem_war/deleteBookById/' + data.bookId,
data: {
"bookId": data.bookId,
"userId": userId
},
dataType: 'json',
success: function (result) {
if (result.code == 0) {
layer.msg(result.msg);
table.reload("table")
} else {
layer.msg(result.msg)
}
}
});
```
后端Controller代码:
```java
@DeleteMapping("/deleteBookById/{bookId}")
@ResponseBody
public Map<String, Object> deleteBookById(@PathVariable("bookId") Integer bookId, @RequestParam Integer userId) {
int deleteResult = adminService.deleteBookById(bookId);
if (!(deleteResult == 1)) {
System.out.println("删除失败");
}
Map<String, Object> result = new HashMap<>();
result.put("code", 0);
result.put("msg", "删除成功");
return result;
}
```
在Controller方法的参数列表中,添加@RequestParam注解,用于获取请求参数中的userId值。
阅读全文
相关推荐






{{ data.bookName }} {{ data.bookAuthor }} {{ data.bookPublish }} ¥{{ data.price }} 减 <input type="text" :value="data.num" readonly class="cOnt"> 加 ¥{{data.total}} 删除 new Vue({ el: '#app', data: { userId: '', list: [] // list: [ // {userId:null,bookName:"图书1",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2}, // {userId:null,bookName:"图书2",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:1}, // {userId:null,bookName:"图书3",image1:"/BookShopSystem_war/cart/xzwxz.png",price:50,num:2} // ] }, //选择或不选择一项 $(".xzWxz").click(function () { if ($(this).hasClass("on")) { $(this).removeClass("on"); } else { $(this).addClass("on"); } var ty = $(".xzWxz.on").length; $(".sXd1").find("font").html(ty); if (ty == es) { $(".ifAll").addClass("on"); } else { $(".ifAll").removeClass("on"); } jsZj(); }); 当我使用未被注释的list,
该代码点击后没有变化,而我使用注释的静态list数组,该代码点击有变化,为什么,未注释的list是能获取到数据并遍历了出来,如何解决

0">
{{bk.bookName}} ¥{{bk.bookPrice}} //列表页——分页 layui.use(['laypage'], function () { var laypage = layui.laypage; laypage.render({ elem: 'houseList' , count: 25 , limit: 5 , theme: '#daba91' , layout: ['page', 'next'] }); }); Vue.config.productionTip = false //阻止vue在启动时生成生产提示 new Vue({ el: "#app", data() { return { bookAll: [] } }, mounted() { var _this = this; axios({ method: 'get', url: 'http://localhost:8080/BookShopSystem_war/getBookAll' }).then(function (result) { var code = result.data.code; var data = result.data.data; if (code == 0) { _this.bookAll = data; } console.log(data) }) } })已省略部分代码,数据都可遍历出来,如何实现分页功能











