背景
首先指定schema[计划的提纲],实时更新最新API,降低集成风险;
早些年:制定word计划文档;
前后端分离:
前端测试后端接口:postman
后端提供接口,需要实时更新最新的消息改动
什么是swagger
号称世界上最流行的Api框架; Restful Api 文档在线自动生成工具 => Api 文档与Api 定义同步更新
直接运行,可以在线测试API接口
支持多种语言
官网:
swagger2+ui
使用swagger
springboot集成swagger
1.新建一个springboot web 项目
2.导入相关依赖
<!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency>
3.编写一个Hello工程
4.配置Swagger
package com.mikey.swagger_demo.config; import org.springframework.context.annotation.Configuration; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * @ProjectName swagger_demo * @Author 麦奇 * @Email biaogejiushibiao@outlook.com * @Date 9/5/19 9:25 AM * @Version 1.0 * @Description: **/ @Configuration @EnableSwagger2 //开启swagger public class SwaggerConfig { }
5.测试页面
http://localhost:8080/swagger-ui.html
配置Swagger的bean实例
配置Swagger扫描接口
Docket.select()
配置Api文档的分组
参考相关博客: