$.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 14:09:40 浏览: 83
如果调用该接口需要传递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值。
阅读全文
相关推荐
![-](https://img-home.csdnimg.cn/images/20241231044833.png)
![-](https://img-home.csdnimg.cn/images/20241231044901.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
{{ 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是能获取到数据并遍历了出来,如何解决
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
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) }) } })已省略部分代码,数据都可遍历出来,如何实现分页功能
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
<?php echo "<script> var bookid = prompt('请输入要删除的图书编号:'); </script>"; $book = $_GET['name']; header ( "Content-type: text/html; charset=utf-8" ); //设置文件编码格式 include_once("con_books.php");//连接数据库 if($bookid) //判断用户是否提交了要删除的图书编号 {//拼接、生成删除操作命令字符串 $sql = "delete from books where bookid = '".$bookid."'"; $result = mysqli_query($conn,$sql); //执行删除操作 if($result) {echo "<script>alert('图书编号为".$bookid."的数据记录已删除成功')</script>";} else{echo "删除失败"; } } else {echo "请输入要删除的图书编号";} ?>为什么php接收不到js的数据?
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![-](https://img-home.csdnimg.cn/images/20241231044930.png)
![-](https://img-home.csdnimg.cn/images/20241231045053.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)