zoukankan      html  css  js  c++  java
  • 学习笔记:SpringMVC集成springfox-swagger2自动生成接口文档

    SpringMVC集成springfox-swagger2自动生成接口文档

    swagger配置步骤
    1:添加maven的jar坐标

    <!--swagger-->
        <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger2</artifactId>
          <version>2.6.1</version>
        </dependency>
        <dependency>
          <groupId>io.springfox</groupId>
          <artifactId>springfox-swagger-ui</artifactId>
          <version>2.6.1</version>
        </dependency>

    2:添加配置 SwaggerConfig.java

    package com.ibaiqi.spider.swagger;
    
    import org.springframework.context.annotation.Bean;
    import org.springframework.context.annotation.Configuration;
    import springfox.documentation.builders.ApiInfoBuilder;
    import springfox.documentation.builders.PathSelectors;
    import springfox.documentation.builders.RequestHandlerSelectors;
    import springfox.documentation.service.ApiInfo;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    /**
     * swagger相关配置
     */
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
        @Bean
        public Docket produceApi() {
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.any())
                    .paths(PathSelectors.any())
                    .build();
        }
    
        // Describe your apis
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    .title("毕业设计")
                    .description("毕业设计LOL助手app")
                    .version("1.0-SNAPSHOT")
                    .build();
        }
    }


    3:浏览显示: 工程路径后加swagger-ui.html

    做产品的程序,才是好的程序员!
  • 相关阅读:
    [日常训练]FJ省夏令营day1
    [vijos1002][NOIP2005]过河
    [poj2446]Chessboard
    [bzoj1854][SCOI2010]游戏
    [模板]匈牙利算法
    [bzoj3670][2014湖北省队互测week2]似乎在梦中见过的样子
    笔记3-27
    笔记3-26
    笔记3-25
    Codeforces891C. Envy
  • 原文地址:https://www.cnblogs.com/asplover/p/12585087.html
Copyright © 2011-2022 走看看