swagger的由來
隨著互聯網技術的發(fā)展故觅,現在的網站架構基本都由原來的后端渲染君账,變成了:前端渲染、先后端分離的形態(tài)榴鼎,而且前端技術和后端技術在各自的道路上越走越遠。
前端和后端的唯一聯系晚唇,變成了API接口巫财;API文檔變成了前后端開發(fā)人員聯系的紐帶,變得越來越重要哩陕,swagger就是一款讓你更好的書寫API文檔的框架平项。
其他API文檔工具
swagger生態(tài)圖
swagger生態(tài)圖
swagger UI 使用方法(選了一種適度封裝之后的)
- 在pom.xml中引入依賴
<dependency>
<groupId>com.spring4all</groupId>
<artifactId>swagger-spring-boot-starter</artifactId>
<version>1.8.0.RELEASE</version>
</dependency>
- 在應用主類中增加@EnableSwagger2Doc注解
@SpringBootApplication
@EnableSwagger2Doc
public class Springboot2Swagger2Application {
public static void main(String[] args) {
SpringApplication.run(Springboot2Swagger2Application.class, args);
}
}
默認情況下就能產生所有當前SpringMVC加載的請求映射文檔
訪問地址:http://localhost:8080/swagger-ui.html
- 參數配置示例
swagger.enabled=true
swagger.title=spring-data-jpa module
swagger.description=Starter for swagger 2.x
swagger.license=Apache License, Version 2.0
swagger.licenseUrl=https://www.apache.org/licenses/LICENSE-2.0.html
swagger.termsOfServiceUrl=https://github.com/dyc87112/spring-boot-starter-swagger
swagger.contact.name=mqXu
swagger.contact.url=http://www.reibang.com/u/822585e5c69a
swagger.contact.email=moqi1977@gmail.com
swagger.base-package=com.springboot.mybatis.controller
swagger.base-path=/**
swagger.exclude-path=/error, /ops/**
swagger UI整體效果
swagger-ui頁面
這下,離開postman也可以愉快地測試接口了并鸵,并且很方便地生成了在線的接口文檔鸳粉,方便前后端聯調扔涧,再也不會滯后了园担。
- 更多特性請移步該項目:github地址