@RequestParam和@PathVariable在开发中的应用

@RequestParam和@PathVariable在开发中的应用

一、前言

在开发中总是遇到@RequestParam和@PathVariable两种注解,特在此记录一下


提示:以下是本篇文章正文内容,下面案例可供参考

二、使用区别

1.1.后端(@PathVariable)

代码如下(示例):

    @GetMapping("/vo/{id}")
    public R<List<Student>> selectAll(@PathVariable String id) {
        List<Student> students = studentService.list(new LambdaQueryWrapper<Student>().eq(Student::getId, id));
        return R.ok(students);
    }

1.2.对应api(@PathVariable)

代码如下(/eauthor 为控制器名):

import request from "@/utils/request";
export function selectAll(id) {
    return request({
        url: `/eauthor/vo/${id}`,//'/eauthor/vo/'+id
        method: 'get'
    })
}

2.1.后端(@RequestParam)

代码如下(示例):

    @GetMapping("/test")
    public R<List<Student>> selectAll(@RequestParam String id) {
        List<Student> students = studentService.list(new LambdaQueryWrapper<Student>().eq(Student::getId, id));
        return R.ok(students);
    }

1.2.对应api(@RequestParam)+

代码如下(/eauthor 为控制器名):

import request from "@/utils/request";
export function selectAll(id) {
    return request({
        url: '/eauthor/test?id='+id,
        method: 'get'
    })
}

总结

@RequestParam和@PathVariable两个注解在开发中遇到的一些问题,在此记录一下。
转发注明明出处:https://editor.csdn.net/md?not_checkout=1&articleId=113114263

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值