当前位置:网站首页>swagger常用注解汇总
swagger常用注解汇总
2022-06-22 05:51:00 【初夏0811】
swagger中常用的注解及其使用位置如下:
| 注解 | 作用 | 使用位置 |
|---|---|---|
| @Api | 表示对类的说明常用参数 | 类上面 |
| @ApiOperation | 说明方法的用途、作用 | 方法上面 |
| @ApiModel | 表示一个返回响应数据的信息 | 响应类 |
| @ApiModelProperty | 描述响应类的属性 | 属性 |
| @ApiIgnore | 忽略某个字段使之不显示在文档中 | 属性 |
@Api:用在请求的类上,表示对类的说明常用参数
| 参数 | 描述 |
|---|---|
| tags | 说明该类的作用,非空时将覆盖value的值 |
| value | 描述类的作用 |
| description | 对api资源的描述,在1.5版本后不再支持 |
| basePath | 基本路径可以不配置,在1.5版本后不再支持 |
| position | 如果配置多个Api 想改变显示的顺序位置,在1.5版本后不再支持 |
| produces | 设置MIME类型列表(output),例:“application/json, application/xml”,默认为空 |
| authorizations | 获取授权列表(安全声明),如果未设置,则返回一个空的授权值 |
| hidden | 默认为false, 配置为true 将在文档中隐藏 |
代码示例:
@Api(tags="登录请求")
@Controller
@RequestMapping(value="/highPregnant")
public class LoginController {
}
@ApiOperation:用在请求的方法上,说明方法的用途、作用
| 参数 | 描述 |
|---|---|
| value | 说明方法的用途、作用 |
| notes | 方法的备注说明 |
| tags | 操作标签,非空时将覆盖value的值 |
| response | 响应类型(即返回对象) |
| responseContainer | 声明包装的响应容器(返回对象类型)。有效值为 “List”, “Set” or “Map”。 |
| responseReference | 指定对响应类型的引用。将覆盖任何指定的response()类 |
| httpMethod | 指定HTTP方法,“GET”, “HEAD”, “POST”, “PUT”, “DELETE”, “OPTIONS” and “PATCH” |
| responseHeaders | 响应头列表 |
| code | 响应的HTTP状态代码。默认 200 |
| hidden | 默认为false, 配置为true 将在文档中隐藏 |
代码示例:
@ResponseBody
@PostMapping(value="/login")
@ApiOperation(value = "登录检测", notes="根据用户名、密码判断该用户是否存在")
public UserModel login(@RequestParam(value = "name", required = false) String account,
@RequestParam(value = "pass", required = false) String password){
}
@ApiModel:用于响应类上,表示一个返回响应数据的信息
示例代码:
@ApiModel(value="用户登录信息", description="用于判断用户是否存在")
public class UserModel implements Serializable{
private static final long serialVersionUID = 1L;
/** * 用户名 */
@ApiModelProperty(value="用户名")
private String account;
/** * 密码 */
@ApiModelProperty(value="密码")
private String password;
}
@ApiModelProperty:用在属性上,描述响应类的属性
| 参数 | 描述 |
|---|---|
| value | 此属性的简要说明。 |
| name | 允许覆盖属性名称 |
| allowableValues | 限制参数的可接受值。1.以逗号分隔的列表 2、范围值 3、设置最小值/最大值 |
| access | 允许从API文档中过滤属性。 |
| notes | 目前尚未使用。 |
| dataType | 参数的数据类型。可以是类名或者参数名,会覆盖类的属性名称。 |
| required | 参数是否必传,默认为false |
| position | 允许在类中对属性进行排序。默认为0 |
| hidden | 允许在Swagger模型定义中隐藏该属性。 |
| example | 属性的示例。 |
| readOnly | 将属性设置为只读 |
| reference | 指定对相应类型定义的引用,覆盖指定的任何参数值 |
代码示例:
@ApiModel(value="用户登录信息", description="用于判断用户是否存在")
public class UserModel implements Serializable{
private static final long serialVersionUID = 1L;
/** * 用户名 */
@ApiModelProperty(value="用户名")
private String account;
/** * 密码 */
@ApiModelProperty(value="密码")
private String password;
}
@ApiIgnore 忽略某个属性,使之不显示在swagger文档中显示
@GetMapping(value ="page")
@ApiOperation(value ="分页查询登录⽇志")
public Result page(@ApiIgnore LogVo vo){
return null;
}
边栏推荐
- TCP连接细节问题
- EPP (enhanced parallel port)
- D3D10 screenshot function saves texture to local
- 单细胞论文记录(part13)--SpaGCN: Integrating gene expression, spatial location and histology to ...
- PID notes
- Single cell paper records (Part8) -- cell2location maps fine grained cell types in spatial transcriptomics
- 单细胞论文记录(part6)--SpaGE: Spatial Gene Enhancement using scRNA-seq
- [soft test] senior system architecture designer learning experience sharing
- 五大常考SQL面试题
- 朗国科技助力OpenHarmony生态繁荣
猜你喜欢

simulink中搭建专家pid控制

SQLServer中的子查询

vscode极简安装教程

Creating GLSL Shaders at Runtime in Unity3D

Ethernet UDP frame contract design

RGB, sRGB and XYZ coordinate conversion

五大常考SQL面试题

单细胞文献学习(part3)--DSTG: deconvoluting spatial transcriptomics data through graph-based AI

Single cell thesis records (part9) -- spatial charting of single cell transcriptomes in lectures

单细胞论文记录(part8)--Cell2location maps fine-grained cell types in spatial transcriptomics
随机推荐
单细胞论文记录(part14)--CoSTA: unsupervised convolutional neural network learning for ST analysis
Design input of Oracle project management system
电热水壶坏了别扔,它很容易修好的!
Unity development - scene asynchronous loading
Air conditioning (daily question 50 in spring)
关于MNIST线性模型矩阵顺序问题
分页工具类 pageUtil<T>
单细胞论文记录(part10)--Computational challenges and opportunities in SRT data
An unordered array of N integers. Find the first number after each element that is larger than it. The time complexity is O (n)
osg编译osgQt
Combinatorial logic described using SystemVerilog gate model
Bat common batch script record
Ethernet UDP frame contract design
D3D learning notes (1) - Introduction to the use conditions of autodraw at so stage
SSM整合所需配置文件及常见配置错误引起的报错
富设备平台突破:基于RK3568的DAYU200进入OpenHarmony 3.1 Release主干
I2C接口
Single cell paper records (Part8) -- cell2location maps fine grained cell types in spatial transcriptomics
为什么我选择 Rust
TCP连接细节问题