zoukankan      html  css  js  c++  java
  • 使用swagger2生成文档

    1.在pom.xml中添加依赖

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

    2.创建Swagger2的配置类SwaggerConfig

    @Configuration  //这是一个配置类
    @EnableSwagger2 //开启在线文档
    public class SwaggerConfig {
        //1.声明api 文档的属性、构建器
        private ApiInfo apiInfo(){
            return new ApiInfoBuilder().title("SpringBoot中使用在线文档构建RestFul风格Apis")
                    .description("gxh").contact("gxh").version("1.0").build();
        }
    
        //2.配置核心配置信息
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2)
                    .apiInfo(apiInfo())
                    .select().apis(RequestHandlerSelectors.basePackage("com.offcn.springbootdemo.controller"))
                    .paths(PathSelectors.any()).build();
        }
    }

    3.在Controller包下的Controller类上添加文档注释

      通过@ApiOperation注解,来给API增加说明;

      通过@ApiImplicitParams、@ApiImplicitParam注解,来给参数增加说明;

    4.运行,查看生成的Swagger2文档

    启动之后,在浏览器中输入:http://localhost:8080/swagger-ui.html

  • 相关阅读:
    Centos6.8下设置gitlab服务开机自启动,关闭防火墙开机自启动
    gitlab设置SSH key
    在centos6.8下安装gitlab遇到的坑
    recyclerView中的方法
    ListView中的方法
    tcp断开时分几步
    get,post区别
    cookie是什么,在什么地方会用到
    http和https的区别
    keystore是个嘛东西
  • 原文地址:https://www.cnblogs.com/gxh494/p/11802292.html
Copyright © 2011-2022 走看看