Swagger测试使用

主要说明

Swagger 目前知道的作用可以整合接口形成测试界面

SpringCloud使用流程如下

1、导入依赖

		<!-- swagger - api接口文档生成、维护 -->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <version>2.8.0</version>
        </dependency>
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger-ui</artifactId>
            <version>2.8.0</version>
        </dependency>

2、添加配置

package com.datasource.myself.common.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * @author yangsisen
 * @createTime 2021-03-12 10:36
 * @description swagger配置类 - api生成、维护配置类
 */
@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi(){
        return new Docket(DocumentationType.SWAGGER_2)
                .pathMapping("/")
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.datasource.myself"))
                .paths(PathSelectors.any())
                .build();
//                .apiInfo(new ApiInfoBuilder()
//                        .title("SpringBoot整合Swagger")//配置页面标题
//                        .description("SpringBoot整合Swagger,详细信息......")//配置页面描述
//                        .version("9.0")//版本信息
//                        .contact(new Contact("啊啊啊啊","blog.csdn.net","aaa@gmail.com"))//内容
//                        .license("The Apache License")
//                        .licenseUrl("http://www.baidu.com")
//                        .build());
    }
}

3、主要注释

序号项目图片备注
1在这里插入图片描述@Api(tags = “基础控制类”)
2在这里插入图片描述@ApiOperation(value = “工程初始化”)
3在这里插入图片描述@ApiModel(value = “学生属性”)
4在这里插入图片描述@ApiModelProperty(“学生名称”)

4、Swagger使用说明

序号项目图片说明
1在这里插入图片描述登录:登录地址为http://localhost:10086/swagger-ui.html
2在这里插入图片描述点击测试
3在这里插入图片描述无参运行,直接获取响应体
4在这里插入图片描述需要传参,传入参数(该测试方法为返回原本你传入的参数)

5、使用过程种可能出现的问题

序号项目图片问题解决
1在这里插入图片描述boot版本过高添加yml配置:spring.mvc.pathmatch.matching-strategy:ant_path_matcher
2
3
  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值