请求方法相关注解的使用

2021-05-20 SpringBootSwagger

# @ApiImplicitParams:用在请求方法上,对多个请求参数增加描述

@ApiImplicitParams({
        @ApiImplicitParam(value = "0不认识 1模糊 2熟记",name = "type"),
        @ApiImplicitParam(value = "页码",name = "page"),
        @ApiImplicitParam(value = "官桥名称",name = "check"),
})
public List<Word> queryList(@PathVariable Integer type,@PathVariable Integer page,@PathVariable Integer  check) {
    return wordService.queryList(type,page,check);
}

# @ApiImplicitParam:可单独使用,或在 @ApiImplicitParams 中使用,给方法的一个请求参数增加描述。

  1. name:参数名
  2. value:描述参数的作用
  3. dataType:参数类型,参数类型,默认String,其它值 dataType="Integer"
  4. defaultValue:参数默认值
  5. required:参数是否必传(true/false)
  6. paramTpye:指定参数放在哪些地方(header/query/path/body/form)

# @ApiResponses:用在请求的方法上,用于表示一组响应

@ApiResponses(value = {
        @ApiResponse(code = 401, message = "服务器认证失败"),
        @ApiResponse(code = 403, message = "资源不存在"),
})
public List<Integer> getCheckNum() {
    return wordService.getCheckNum();
}

# @ApiResponse:用在@ApiResponses中,一般用于表达一个错误的响应信息,注解参数:

  • code:数字,如 400
  • message:信息,如 “参数填写错误”
  • response:抛出异常的类

# @ApiIgnore: 使用该注解忽略这个API

上次更新: 2 年前