Springboot集成knife4j實(shí)現(xiàn)風(fēng)格化API文檔
更新時(shí)間:2020年12月25日 09:14:00 作者:pengsn
這篇文章主要介紹了Springboot如何集成knife4j實(shí)現(xiàn)風(fēng)格化API文檔,幫助大家更好的使用springboot框架,感興趣的朋友可以了解下
POM引入插件
<dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <!--在引用時(shí)請(qǐng)?jiān)趍aven中央倉庫搜索最新版本號(hào) --> <version>2.0.3</version> </dependency>
配置加載
package com.pengsn.apiserver.videoconference.config; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Import; import com.github.xiaoymin.knife4j.spring.annotations.EnableKnife4j; import springfox.bean.validators.configuration.BeanValidatorPluginsConfiguration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.service.Contact; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; /** * 配置 */ @Configuration @EnableSwagger2 @EnableKnife4j @Import(BeanValidatorPluginsConfiguration.class) public class SwaggerConfiguration { @Bean(value = "defaultApi2") public Docket defaultApi2() { Docket docket = new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()) .select() // 這里指定Controller掃描包路徑 .apis(RequestHandlerSelectors.basePackage( "com.pengsn.apiserver.videoconference.business")) .paths(PathSelectors.any()).build(); return docket; } private ApiInfo apiInfo() { Contact contact = new Contact("pengsn", "", ""); return new ApiInfoBuilder().title("視頻會(huì)議接口描述"). description("視頻會(huì)議接口描述").contact(contact).version("1.0").build(); } }
注解使用
- @Api(tags="controller description"); 作用于 類
- @ApiOperator(value="接口名稱", notes="接口描述") 作用于 方法
- @ApiOperationSupport(order=1) 排序
界面顯示
以上就是Springboot集成knife4j實(shí)現(xiàn)風(fēng)格化API文檔的詳細(xì)內(nèi)容,更多關(guān)于Springboot集成knife4j的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
一個(gè)Servlet是如何處理多個(gè)請(qǐng)求的?
以前我一直以為一個(gè)Servlet只能處理一個(gè)請(qǐng)求,后來發(fā)現(xiàn)是自己太菜了,可以借助攜帶一個(gè)參數(shù)來完成多個(gè)請(qǐng)求的處理,根據(jù)參數(shù)的不同,在核心的service方法中調(diào)用不同的業(yè)務(wù)方法,來實(shí)現(xiàn)處理多個(gè)servlet請(qǐng)求的目的,廢話不多說,直接上代碼,需要的朋友可以參考下2021-06-06解決logback-classic 使用testCompile的打包問題
這篇文章主要介紹了解決logback-classic 使用testCompile的打包問題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-07-07spring基于注解配置實(shí)現(xiàn)事務(wù)控制操作
這篇文章主要介紹了spring基于注解配置實(shí)現(xiàn)事務(wù)控制操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2021-09-09springboot遠(yuǎn)程執(zhí)行服務(wù)器指令
這篇文章主要介紹了springboot遠(yuǎn)程執(zhí)行服務(wù)器指令,本例是java遠(yuǎn)程連接到服務(wù)器,去抓取查詢kubesphere中的etcd日志,并返回,需要的朋友可以參考下2023-09-09ElasticSearch學(xué)習(xí)之多條件組合查詢驗(yàn)證及示例分析
這篇文章主要為大家介紹了ElasticSearch 多條件組合查詢驗(yàn)證及示例分析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02Spring Boot中@ConditionalOnProperty的使用方法
這篇文章主要給大家介紹了關(guān)于Spring Boot中@ConditionalOnProperty的使用方法,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者使用Spring Boot具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12