@thatcompany/axios@thatcompany/axios
主页
  • 介绍
  • 效果
  • 引入
  • 请求类型
  • 功能类型
  • 基类
  • restful风格类
  • 服务规范
  • 日志服务
  • 安全服务
  • 通知服务
  • 文件服务
主页
  • 介绍
  • 效果
  • 引入
  • 请求类型
  • 功能类型
  • 基类
  • restful风格类
  • 服务规范
  • 日志服务
  • 安全服务
  • 通知服务
  • 文件服务
  • 请求装饰器

RequestMapping

注解用于类上

  • 用于定义请求的基本路径映射。
  • 可以理解为前缀路径。
  • 若类上有RequestMapping注解,则类中的所有方法都将以该注解的路径为前缀。

PS: 若项目配置了代理就写代理地址。

如下代码的findById方法的Get请求路径为https://test.thatcoder.cn/order/list/{id}

import { RequestMapping, GetMapping } from '@thatcompany/axios';

@RequestMapping('https://test.thatcoder.cn/order')
class OrderMapper {
    @GetMapping('/{id}')
    async findById(id: number) {}
}

MethodMapping

下列实际请求装饰器都默认接受一个字符串参数,即请求路径。

都能接受花括号{},表示路径参数,会识别参数名称并自动替换为对应的实际值。

@RequestMapping('https://test.thatcoder.cn')
class OrderMapper {
    // 实际请求路径为 https://test.thatcoder.cn/user/123/order/456
    @GetMapping('/user/{userId}/order/{orderId}')
    async findUserOrderById(userId: number = 123, orderId: number = 456) {}
}

GetMapping

注解用于方法上

  • 用于定义为Get请求。
  • 参数为请求路径。
  • 参数为空时 @GetMaping() 等同于 @GetMapping("")。

DeleteMapping

与GetMapping类似,用于定义为Delete请求。

PostMapping

注解用于方法上

  • 用于定义为Post请求。
  • 参数为请求路径。
  • 参数为空时 @PostMapping() 等同于 @PostMapping("")。

PutMapping

与PostMapping类似,用于定义为Put请求。

Last Updated:
Contributors: 钟意