zoukankan      html  css  js  c++  java
  • 初学SpringBoot集成Swagger的使用

    SpringBoot 集成Swagger

    1.新建一个SpringBoot 项目

    2.导入依赖

    有两个依赖

    Swagger2

    <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger2 -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger2</artifactId>
        <version>2.9.2</version>
    </dependency>
    
    

    Swagger ui

    <!-- https://mvnrepository.com/artifact/io.springfox/springfox-swagger-ui -->
    <dependency>
        <groupId>io.springfox</groupId>
        <artifactId>springfox-swagger-ui</artifactId>
        <version>2.9.2</version>
    </dependency>
    
    

    3.配置Swagger ==》config

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    }
    

    4.测试运行

    项目跑起来后,即可去浏览器键入下面的地址,就可以看到Swagger的接口管理页面
    http://localhost:8080/swagger-ui.html

    SwaggerConfig配置文件内容

    @Bean
        public Docket createRestApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //RequestHandlerSelectors()选择扫描方式
                //加了ApiOperation注解的类,才生成接口文档
                .apis(RequestHandlerSelectors.withClassAnnotation(ApiOperation.class))
                //扫描指定包下的类,才生成接口文档
                .apis(RequestHandlerSelectors.basePackage("cn.cnkimall.modules.sys.controller"))
                .paths(PathSelectors.any())
                .build()
                .securitySchemes(security());
        }
    
    
        private ApiInfo apiInfo(String title, String version, String description) {
            return new ApiInfoBuilder()
                    .title(title)                 //标题
                    .description(description)     //说明
                    .version(version)             //版本号
                    .build();
        }
    
  • 相关阅读:
    用Total Commander for Android管理应用程序
    我的zsh简单设置
    C# Newtonsoft.Json 使用
    Wireshark 抓包 test
    C# 调用API test
    C# 委托 的语法 之一
    C# 对象初始化器 和数组初始化语法
    C 语言 数据类型长度
    vue 使用 test
    test
  • 原文地址:https://www.cnblogs.com/zzzqi/p/13082571.html
Copyright © 2011-2022 走看看