SpringBoot開啟Swagger并配置基本信息方式
更新時間:2024年05月22日 12:11:12 作者:yui方木
這篇文章主要介紹了SpringBoot開啟Swagger并配置基本信息方式,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
前后端分離:前后端交互:API
前后端集成聯(lián)調(diào),前后端人員無法及時協(xié)商
解決方案
- 首先制定schema[計劃的提綱],實時更新最新API,降低集成風(fēng)險
- Swagger
Swagger
- 世界上最流行的API框架
- Restful API 文檔在線自動生成工具–>API文檔與API定義同步更新
- 可以在線直接運行,直接測試
- 支持多種語言:Java、PHP…
在項目中使用swagger:springfox
- swagger2
- ui
Springboot集成Swagger
導(dǎo)包:
<!-- swagger --> <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.9.2</version> </dependency> <!-- swagger-ui --> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.9.2</version> </dependency>
配置swagger:
package com.example.config;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@Configuration
/**開啟Swagger2*/
@EnableSwagger2
public class SwaggerConfig {
}
然后就可以訪問swagger頁面:
/swagger-ui.html

配置swagger
進ApiInfo這個類看看,有什么Api配置屬性:


SwaggerConfig配置類:
配置ApiInfo:
@Configuration
/*開啟Swagger2*/
@EnableSwagger2 /* :/swagger-ui.html */
public class SwaggerConfig {
//配置Swagger的Docket的bean實例
@Bean
public Docket docket(){
//配置文檔信息
return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo());
}
//配置apiinfo
private ApiInfo apiInfo(){
//作者信息
Contact contact = new Contact("fzl","https://blog.csdn.net/weixin_44976835","1403275028@qq.com");
return new ApiInfo(
"Epidemic Swagger",
"fzl最帥",
"1.0",
"https://blog.csdn.net/weixin_44976835",
contact,
"Apache 2.0",
"http://www.apache.org/licenses/LICENSE-2.0",
new ArrayList()
);
}
}
可以配置swagger-ui.html頁面信息,配置完變成了:

沒什么大用,就是更改一個文檔說明,還能標(biāo)注個作者什么的^ .^
總結(jié)
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
MyBatis批量插入大量數(shù)據(jù)(1w以上)
MyBatis進行批量插入數(shù)時,一次性插入超過一千條的時候MyBatis開始報錯,本文主要介紹了MyBatis批量插入大量數(shù)據(jù)的解決方法,感興趣的可以了解一下2022-01-01
Spring 使用 feign時設(shè)置header信息的操作
這篇文章主要介紹了Spring 使用 feign時設(shè)置header信息的操作,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-08-08
Netty源碼分析NioEventLoop處理IO事件相關(guān)邏輯
這篇文章主要介紹了Netty源碼分析NioEventLoop處理IO事件相關(guān)邏輯,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪2022-03-03

