springboot swagger 接口文檔分組展示功能實(shí)現(xiàn)
例如將 controller 分成四類(lèi),分別放到四個(gè)包下:
xxx.xxx.xxx.controller.manage xxx.xxx.xxx.controller.client xxx.xxx.xxx.controller.authority xxx.xxx.xxx.controller.common
SwaggerConfig.java:
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.ParameterBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.schema.ModelRef;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.service.Parameter;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@RefreshScope
@Configuration
@EnableSwagger2
public class SwaggerConfig {
@Value("${system.swagger_show}")
private boolean swaggerShow;
@Bean
public Docket manageGroup() {
return this.buildDocket( "管理端接口","xxx.xxx.xxx.controller.manage" );
}
@Bean
public Docket clientGroup() {
return this.buildDocket( "移動(dòng)端接口","xxx.xxx.xxx.controller.client" );
}
@Bean
public Docket authorityGroup() {
return this.buildDocket( "權(quán)限相關(guān)接口","xxx.xxx.xxx.controller.authority" );
}
@Bean
public Docket commonGroup() {
return this.buildDocket( "數(shù)據(jù)字典、行政區(qū)域公共接口","xxx.xxx.xxx.controller.common" );
}
private Docket buildDocket( String groupName,String basePackage ){
return new Docket(DocumentationType.SWAGGER_2)
.groupName( groupName )
.enable(this.swaggerShow)
.produces(Collections.singleton(MediaType.APPLICATION_JSON_VALUE))
.genericModelSubstitutes(ResponseEntity.class)
.forCodeGeneration(false)
.useDefaultResponseMessages(false)
.pathMapping("/")
.select()
.apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
.apis(RequestHandlerSelectors.basePackage( basePackage ))
.paths(PathSelectors.any())
.build()
.globalOperationParameters( setHeaderToken() )
.directModelSubstitute(java.sql.Timestamp.class, java.sql.Date.class)
.apiInfo(apiInfo());
}
private List<Parameter> setHeaderToken() {
ParameterBuilder tokenPar = new ParameterBuilder();
List<Parameter> pars = new ArrayList<>();
tokenPar.name("witToken").description("登錄token").modelRef(new ModelRef("string")).parameterType("header").required(false).build();
pars.add(tokenPar.build());
return pars;
}
private ApiInfo apiInfo() {
ApiInfo apiInfo = new ApiInfoBuilder()
.title("xxx系統(tǒng)( xxx) API")
.description("xxx系統(tǒng)( xxx) API")
.license(null)
.licenseUrl(null)
.contact(new Contact("developer", "", "developer@xxx.com"))
.version("1.0")
.build();
return apiInfo;
}
}
效果:

到此這篇關(guān)于springboot swagger 接口文檔分組展示的文章就介紹到這了,更多相關(guān)springboot swagger 接口文檔內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
SpringMVC請(qǐng)求的路徑變量里面寫(xiě)正則表達(dá)式的方法
這篇文章主要介紹了SpringMVC請(qǐng)求的路徑變量里面寫(xiě)正則表達(dá)式的相關(guān)知識(shí),本文給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09
一篇超詳細(xì)的Spring Boot整合Mybatis文章
大家都知道springboot搭建一個(gè)spring框架只需要秒秒鐘。下面通過(guò)實(shí)例代碼給大家介紹一下springboot與mybatis的完美融合,非常不錯(cuò),具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2021-07-07
Spring多數(shù)據(jù)源切換失敗,發(fā)現(xiàn)與事務(wù)相關(guān)問(wèn)題
這篇文章主要介紹了Spring多數(shù)據(jù)源切換失敗,發(fā)現(xiàn)與事務(wù)相關(guān)問(wèn)題,具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2024-01-01
Java線程的并發(fā)工具類(lèi)實(shí)現(xiàn)原理解析
本文給大家講解Java線程的并發(fā)工具類(lèi)的一些知識(shí),通過(guò)適用場(chǎng)景分析大數(shù)據(jù)量統(tǒng)計(jì)類(lèi)任務(wù)的實(shí)現(xiàn)原理和封裝,多個(gè)示例代碼講解的非常詳細(xì),對(duì)java線程并發(fā)工具類(lèi)相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)下吧2021-06-06
如何使用 IntelliJ IDEA 編寫(xiě) Spark 應(yīng)用程序(Sc
本教程展示了如何在IntelliJIDEA中使用Maven編寫(xiě)和運(yùn)行一個(gè)簡(jiǎn)單的Spark應(yīng)用程序(例如WordCount程序),本文通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧2024-11-11
SpringBoot中打印SQL語(yǔ)句的幾種方法實(shí)現(xiàn)
本文主要介紹了SpringBoot中打印SQL語(yǔ)句的幾種方法實(shí)現(xiàn),,通過(guò)打印SQL語(yǔ)句可以幫助開(kāi)發(fā)人員快速了解數(shù)據(jù)庫(kù)的操作情況,進(jìn)而進(jìn)行性能分析和調(diào)試,感興趣的可以了解一下2023-11-11
Kotlin 基礎(chǔ)教程之?dāng)?shù)組容器
這篇文章主要介紹了Kotlin 基礎(chǔ)教程之?dāng)?shù)組容器的相關(guān)資料,需要的朋友可以參考下2017-06-06
Java編程之多線程死鎖與線程間通信簡(jiǎn)單實(shí)現(xiàn)代碼
這篇文章主要介紹了Java編程之多線程死鎖與線程間通信簡(jiǎn)單實(shí)現(xiàn)代碼,具有一定參考價(jià)值,需要的朋友可以了解下。2017-10-10
Spring Cloud Feign實(shí)現(xiàn)動(dòng)態(tài)URL
本文主要介紹了Spring Cloud Feign實(shí)現(xiàn)動(dòng)態(tài)URL,文中通過(guò)示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02

