Vue和SpringBoot项目前端请求和后端接收的URL格式

Vue和SpringBoot项目前端请求和后端接收的URL格式

模版字符串

  1. `const baseUrl = ‘https://api.example.com/users’;
    const userId = 123;
    const userName = ‘JohnDoe’;

// 使用模板字符串构建URL
const url = ${baseUrl}?id=${userId}&name=${encodeURIComponent(userName)};`

字符串拼接

1.路径直接携带参数
前端发送:let url=this.BASE_URL+'/v1/contents/delete/'+row.id
后端接收:@RequestMapping("/v1/contents/")
@DeleteMapping("/delete/{id}")

public JsonResult deleteContentById(@PathVariable int id){ iContentService.deleteContentById(id); return JsonResult.ok(); }

  1. 使用?拼接携带参数

前端发送: let url=this.BASE_URL+'/v1/users/delete?id='+id
后端接收:@RequestMapping("/v1/users")

@DeleteMapping("/delete")
public JsonResult deleteUserById(Integer id){
    // let url=this.BASE_URL+'/v1/users/delete/'+id
    //使用该方法传递数据时,@DeleteMapping("/delete/{id}")中要加入传过来数据的占位符`


    // let url=this.BASE_URL+'/v1/users/delete?id='+id
    //使用该方法时不用在Mapping中接收

    iUserService.deleteUserById(id);
    return JsonResult.ok();
}
  1. 多个参数
    前端发送:let url=this.BASE_URL+'/v1/contents/'+type+'/'+categoryId+'/index'
    后端接收:
    @GetMapping("/{type}/{categoryId}/index")

    public JsonResult getContentsByTypeAndCategoryId(@PathVariable Integer type,@PathVariable Integer categoryId){

    `log.debug(“获取的数据{}==》{}”,type,categoryId);

    List<ContentIndexVO> vo=iContentService.getContentByTypeAndCategoryId(type,categoryId);
    return JsonResult.ok(vo);
    

    }`

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值