Spring Boot中级篇-集成Swagger2分组文档

Swagger配置文件
这里配置两个分组admin【后台管理接口】、wechat【微信管理接口】

@Configuration
@EnableSwagger2
public class Swagger2 {

    public static final String SWAGGER_SCAN_ADMIN_PACKAGE = "com.jacksony.module.admin.controller";
    public static final String ADMIN_VERSION = "1.0.0";
    public static final String SWAGGER_SCAN_WX_PACKAGE = "com.jacksony.module.wechat.controller";
    public static final String WX_VERSION = "1.0.0";

    @Bean
    public Docket createAdminRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("后台管理接口")
                .apiInfo(apiAdminInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_ADMIN_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/admin/.*"))//可以根据url路径设置哪些请求加入文档,忽略哪些请求
                .build();
    }
    private ApiInfo apiAdminInfo() {
        return new ApiInfoBuilder()
                .title("后台管理接口")//设置文档的标题
                .description("后台数据管理")//设置文档的描述->1.Overview
                .version(ADMIN_VERSION)//设置文档的版本信息-> 1.1 Version information
                .build();
    }

    @Bean
    public Docket createWxRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("微信管理接口")
                .apiInfo(apiWxInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_WX_PACKAGE))//api接口包扫描路径
                .paths(PathSelectors.regex(".*/weixin/.*"))//可以根据url路径设置哪些请求加入文档,忽略哪些请求
                .build();
    }
    private ApiInfo apiWxInfo() {
        return new ApiInfoBuilder()
                .title("微信管理接口")//设置文档的标题
                .description("微信开发接口实现的文档")//设置文档的描述->1.Overview
                .version(WX_VERSION)//设置文档的版本信息-> 1.1 Version information
                .build();
    }
}

SpringBoot可以集成Knife4j来实现接口文档和接口测试工具的功能。集成的具体步骤如下: 1. 在项目的pom.xml文件中添加Knife4j的依赖: ```xml <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <version>3.0.1</version> </dependency> ``` 2. 配置Knife4j的相关参数,例如在application.properties或者application.yml文件中添加如下配置: ```yaml knife4j: swagger-ui: enabled: true title: 接口文档 description: 接口文档描述 contact.name: 联系人姓名 contact.url: 联系人网址 contact.email: 联系人邮箱 enable: true ``` 3. 启动SpringBoot应用程序,访问"http://localhost:port/doc.html"就可以看到整合了Knife4j的接口文档界面。 通过集成Knife4j,SpringBoot可以更方便地生成和管理接口文档,同时还提供了接口测试的便利工具。总的来说,Knife4j是一个小巧、轻量但功能强大的工具,非常适合初中级程序员进行增删改查等常用工作。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [springboot整合Knife4j--token头验证](https://blog.youkuaiyun.com/yhyyhyyhygood/article/details/128183568)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* *3* [SpringBoot集成Knife4j:最好用的Swagger接口文档和接口测试工具](https://blog.youkuaiyun.com/qq_43090226/article/details/129842596)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值