SpringBoot2.xxx 开发使用Swagger2测试工具简录

2 篇文章 0 订阅
2 篇文章 0 订阅

一、Swagger2

    SpringBoot2.xxx  maven 项目中引入Swagger2两种方式:

    1、官方依赖包

<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、第三方依赖包

<dependency>
    <groupId>com.spring4all</groupId>
    <artifactId>swagger-spring-boot-starter</artifactId>
    <version>1.7.0.RELEASE</version>
</dependency>

javaConfig配置代码案列:  

@Configuration
@EnableSwagger2
public class SwaggerConfig
{
    /**
     * 用于配置swagger2,包含文档基本信息
     */
    @Bean
    public Docket createRestApi()
    {
        return new Docket(DocumentationType.SWAGGER_2)              
//                .host("域名/ip.com") //配置域名、对应ip等具体服务器
                .pathMapping("/") //本地测试配置路径
                // 用来创建该API的基本信息,展示在文档的页面中(自定义展示的信息)
                .apiInfo(apiInfo())
                // 设置哪些接口暴露给Swagger展示
                .select()
                // 灵活使用 扫描所有有注解的api
//                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                // 扫描指定controller层包下有注解的对外暴露接口
                .apis(RequestHandlerSelectors.basePackage("com.xx.controller"))
                // 扫描所有 .apis(RequestHandlerSelectors.any())
                .paths(PathSelectors.any())
                .build();

    }

    /**
     * 添加摘要信息
     */
    private ApiInfo apiInfo()
    {
        // 用ApiInfoBuilder进行定制
        return new ApiInfoBuilder()
                .title("springboot利用swagger构建api文档")
                .description("简单优雅的restfun风格")
                .contact(new Contact("dxw", null, null))// 作者信息
                .termsOfServiceUrl("http:/xxx/xxx") 
                .version("版本号:1.0" )// 版本 
                .build();
    }
}

详细说明参考:https://blog.csdn.net/p_programmer/article/details/89426257

二、Postman

   详情参看来源:https://www.jianshu.com/p/ad7295d7bb41

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值