@RequestParam()和@RequestBody() 和 @PathVariable()

本文介绍了在SpringBoot中如何使用@RequestParam处理GET请求中的多个参数,以及如何使用@RequestBody处理POST请求中的完整对象,同时展示了@PathVariable在处理单个路径参数的应用。还给出了前端JavaScript进行API调用的示例。
摘要由CSDN通过智能技术生成

@RequestParam ——多个参数

// 后端 Springboot 
@GetMapping("/orders/selectAll")
    public String getAllOrders(@RequestParam("uid") String uid, @RequestParam("status") String status) {
        // 处理参数
        return "Received UID: " + uid + ", Status: " + status;
    }

// 前端js
	this.$request.get('/orders/selectByUidAndStatus?uid=' + this.user.id + '&status=' + 'stay').then(res => {
					if (res.code === '200') {
						this.unStayOrdersMsg = res.data || []
					} else {
						console.log(res.msg)
					}
				})

@RequestBody —— 整个对象

@PathVariable —— 单个参数

    /**
     * 批量删除
     */
    @DeleteMapping("/delete/batch")
    public Result deleteBatch(@RequestBody List<Integer> ids) {
        ordersService.deleteBatch(ids);
        return Result.success();
    }

    /**
     * 删除
     */
    @DeleteMapping("/delete/{id}")
    public Result deleteById(@PathVariable Integer id) {
        collectService.deleteById(id);
        return Result.success();
    }

前端js

http://localhost:9090/collect/delete/44

this.$request.delete('/collect/delete/batch', {data: this.ids}).then(res = >{})


this.$request.delete('/collect/delete/' + id).then(res => {

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值