首页 > 百科知识 正文

用了Swagger2后接口设计文档(swagger接口顺序)

时间:2023-11-21 21:18:32 阅读:684 作者:殺死人类

用了Swagger2后接口设计文档(swagger接口顺序)-第1张

pom文件加入如下依赖

<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency>

启动类上加入@EnableSwagger2注解

@EnableSwagger2 @SpringBootApplication @MapperScan("com.st.blog.dao") public class BlogApplication { public static void main(String[] args) { SpringApplication.run(BlogApplication.class, args); } }

增加配置类

用了Swagger2后接口设计文档(swagger接口顺序)-第2张

访问http://localhost:8080/swagger-ui.html

用了Swagger2后接口设计文档(swagger接口顺序)-第3张

取其中一个例子,示例返回以及要填的各种参数都已经帮你弄好了,直接填入参数就能测试,非常方便

用了Swagger2后接口设计文档(swagger接口顺序)-第4张

导出文档

可以将测试页面导出为各种格式的文档,不再介绍

Swagger注解

可以用Swagger提供的注解,对显示在页面的上的各种参数进行描述,和代码耦合性比较高,不再演示

@Api:修饰整个类,描述Controller的作用

@ApiOperation:描述一个类的一个方法,或者说一个接口

@ApiParam:单个参数描述

@ApiModel:用对象来接收参数

@ApiProperty:用对象接收参数时,描述对象的一个字段

@ApiResponse:HTTP响应其中1个描述

@ApiResponses:HTTP响应整体描述

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

@ApiError :发生错误返回的信息

@ApiImplicitParam:一个请求参数

@ApiImplicitParams:多个请求参数

本文为小编原创文章,首发于Java识堂,一个高原创,高收藏,有干货的微信公众号,一起成长,一起进步,欢迎关注

版权声明:该问答观点仅代表作者本人。如有侵犯您版权权利请告知 cpumjj@hotmail.com,我们将尽快删除相关内容。