SpringBoot 配置swagger分组

1. 引入依赖

<!--swagger-->
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger2</artifactId>
  <version>2.9.2</version>
</dependency>
<!--swagger ui-->
<!--swagger-ui.html 可以访问-->
<dependency>
  <groupId>io.springfox</groupId>
  <artifactId>springfox-swagger-ui</artifactId>
  <version>2.9.2</version>
</dependency>
<!--swagger-bootstrap-ui-->
<!--bootstrap: 基于swagger的一个视图框架 doc.html-->
<dependency>
  <groupId>com.github.xiaoymin</groupId>
  <artifactId>swagger-bootstrap-ui</artifactId>
  <version>1.9.2</version>
</dependency>

2. 配置类

@Configuration
@EnableSwagger2 //启用swagger
public class SwaggerConfig {

    //一个Docker代表一个swagger的分组: 一个分组中可以将多个匹配的Controller进行管理
    @Bean
    public Docket adminApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("adminApi")
                .apiInfo(adminApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/admin/.*")))
                .build();
    }

    private ApiInfo adminApiInfo() {
        return new ApiInfoBuilder()
                .title("尚融宝后台管理系统-API文档")
                .description("本文档描述了尚融宝后台管理系统接口")
                .version("1.0")
                .contact(new Contact("liush", "http://liush.com", "[email protected]"))
                .build();
    }

    @Bean
    public Docket webApiConfig() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")
                .apiInfo(webApiInfo())
                .select()
                //只显示admin路径下的页面
                .paths(Predicates.and(PathSelectors.regex("/api/.*")))
                .build();

    }

    private ApiInfo webApiInfo() {
        return new ApiInfoBuilder()
                .title("尚融宝用户前台系统-API文档")
                .description("本文档描述了尚融宝用户前台系统接口")
                .version("1.0")
                .contact(new Contact("liush", "http://liush.com", "[email protected]"))
                .build();
    }
}

猜你喜欢

转载自blog.csdn.net/qq_45037155/article/details/129780173