springboot swagger 接口文檔分組展示功能實現(xiàn)
更新時間:2024年03月27日 10:14:01 作者:狄龍疤
這篇文章主要介紹了springboot swagger 接口文檔分組展示功能實現(xiàn),本文通過實例代碼給大家介紹的非常詳細(xì),感興趣的朋友跟隨小編一起看看吧
例如將 controller 分成四類,分別放到四個包下:
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( "移動端接口","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)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Java中線程狀態(tài)+線程安全問題+synchronized的用法詳解
這篇文章主要介紹了Java中線程狀態(tài)+線程安全問題+synchronized的用法詳解,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價值,需要的朋友可以參考下2022-04-04
一文解析Java開發(fā)中高頻使用的網(wǎng)絡(luò)協(xié)議
對于Java開發(fā)者而言,無需深入?yún)f(xié)議底層實現(xiàn),但必須掌握常用協(xié)議的核心原理,應(yīng)用場景和Java代碼實操,才能高效開發(fā)網(wǎng)絡(luò)通信相關(guān)功能,下面我們就來重點解析一下Java開發(fā)中高頻使用的網(wǎng)絡(luò)協(xié)議吧2026-04-04
利用Spring Cloud Config結(jié)合Bus實現(xiàn)分布式配置中心的步驟
這篇文章主要介紹了利用Spring Cloud Config結(jié)合Bus實現(xiàn)分布式配置中心的相關(guān)資料,文中通過示例代碼將實現(xiàn)的步驟一步步介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友下面來一起看看吧2018-05-05

