zoukankan      html  css  js  c++  java
  • Spring Boot 整合 swagger2 自动生成 RESTFul API 文档

    1)首先编辑pom.xml添加依赖

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

    2)创建Swagger配置文件

    package pro.kkpai.springbootswagger.config;
    
    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.service.Contact;
    import springfox.documentation.spi.DocumentationType;
    import springfox.documentation.spring.web.plugins.Docket;
    import springfox.documentation.swagger2.annotations.EnableSwagger2;
    
    
    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    
        @Bean
        public Docket RestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select()
                    .apis(RequestHandlerSelectors.basePackage("pro.kkpai.springbootswagger.controller"))
                    .paths(PathSelectors.any())
                    .build();
        }
    
        private ApiInfo apiInfo() {
            return new ApiInfoBuilder()
                    //标题
                    .title("这是Swagger的RESTFul API")
                    //描述
                    .description("一个用户管理系统的RESTFul API")
                    //联系方式
                    .contact(new Contact("kkpai", "https://kkpai.pro", "whatisnicedream@qq.com"))
                    //服务条款url
                    .termsOfServiceUrl("https://kkpai.pro")
              
    //版本 .version("1.0") .build(); } }

     3)Controller层类添加注解

      @Api

    未完。。。

  • 相关阅读:
    Qt QApplication 类简介--Qt 类简介专题(四)
    回调函数
    C++类型转换总结
    Debug Error
    C++回调函数(callback)的使用
    Nokia5230连接电脑无线上网
    photoshop cs6\cs5找不到扫描仪的解决办法(Twain_32.8BA补丁下载)
    UML类图几种关系的总结
    实现单点登录
    poj 1151Atlantis线段树求矩形面积并解题报告
  • 原文地址:https://www.cnblogs.com/1x11/p/9736173.html
Copyright © 2011-2022 走看看