當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Springfox-swagger使用详解
生活随笔
收集整理的這篇文章主要介紹了
Springfox-swagger使用详解
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
Springfox-swagger使用詳解
- 什么是Swagger?
- Swagger的具體使用
- 一、導入依賴
- 二、建立Swagger配置類
- 三、通過Swagger測試接口
- 引用
什么是Swagger?
是一個開源的API Doc的框架Swagger的具體使用
一、導入依賴
<dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger2</artifactId><version>2.9.2</version> </dependency> <dependency><groupId>io.springfox</groupId><artifactId>springfox-swagger-ui</artifactId><version>2.9.2</version> </dependency>二、建立Swagger配置類
@Configuration @EnableSwagger2 //開啟swagger2 public class SwaggerConfig {@Beanpublic Docket docket(Environment environment){Profiles profiles = Profiles.of("dev");boolean enable = environment.acceptsProfiles(profiles); //根據當前開發環境來決定是否要運行swaggerreturn new Docket(DocumentationType.SWAGGER_2).groupName("InformationController") //我們通過建立多個Docket類并給不同的groupname區分不同人員的文檔// 修改swagger-ui.html界面的基礎顯示信息.apiInfo(apiInfo())//判斷是否是開發模式,來決定是否開啟swagger2.enable(enable)// apis 配置掃描接口的方式.select().apis(RequestHandlerSelectors.basePackage("com.wyw.checkinsystem.Controller")) //限定掃描的Controller目錄.paths(PathSelectors.ant("/loginstu")) //限定掃描的請求鏈接.build();//被Controller return的實體類都會顯示在model中,我們也可以通過注釋標注,為Models添加信息//同樣,我們可以使用另外兩個注釋,為controller中的方法及其參數添加信息}private ApiInfo apiInfo(){Contact contact = new Contact("name", "", "");return new ApiInfo("Ostrich5yw Api Documentation","Api Documentation","1.0","urn:tos",contact,"Apache 2.0","http://www.apache.org/licenses/LICENSE-2.0",new ArrayList<VendorExtension>());}三、通過Swagger測試接口
我們通過Swagger可以直接填入數據請求來測試Controller中的接口 PS:進入http://localhost:端口號/swagger-ui.html查看swagger日志引用
本文根據遇見狂神說的Docker視頻編寫。
總結
以上是生活随笔為你收集整理的Springfox-swagger使用详解的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 增强中获取屏幕值的一句很实用代码…
- 下一篇: gradle idea java ssm