zoukankan      html  css  js  c++  java
  • Swagger使用

      对于前后端分离的项目,在接口测试的时候,可以使用postman、poster等接口测试工具。当然,也可以使用swagger

    pom.xml文件

            <!-- swagger -->
            <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>

    SwaggerConfig.java

    @Configuration
    @EnableSwagger2
    public class SwaggerConfig {
    
        @Bean
        public Docket createRestApi(){
            return new Docket(DocumentationType.SWAGGER_2).apiInfo(apiInfo()).select()
                    .apis(RequestHandlerSelectors.any()).paths(PathSelectors.any()).build();
        }
    
        private ApiInfo apiInfo(){
            return new ApiInfoBuilder().build();
        }
    }

    可视化界面地址:

    http://localhost:8001/swagger-ui.html#/

    访问SysUserController测试

    三个方法分别对应Controller的三个方法

     测试findAll方法:

    点击findAll栏目

    点击try it out

     点击Execute

     获取数据:

    测试文件下载:

    点击下载文件的方法

     

     输入参数(有参数的话),执行

     点击download file便可下载文件

    Reference:

    wuqke, Swagger介绍及使用, https://www.jianshu.com/p/349e130e40d5

  • 相关阅读:
    Java设计模式——单例模式
    重新学习MyBatis-逆向工程
    重新学习MyBatis(六)
    重新学习MyBatis(五)
    重新学习Mybatis(四)
    重新学习MyBatis(三)
    重新学习Mybatis(二)
    Java设计模式重新出发
    回归问题常用的损失函数总结
    Matlab绘图局部放大
  • 原文地址:https://www.cnblogs.com/ryelqy/p/14119810.html
Copyright © 2011-2022 走看看