其他分享
首页 > 其他分享> > 谷粒学苑项目第一天-配置Swagger2进行接口测试

谷粒学苑项目第一天-配置Swagger2进行接口测试

作者:互联网

1.引入相关依赖

    <!--swagger-->
        <dependency>
            <groupId>io.springfox</groupId>
            <artifactId>springfox-swagger2</artifactId>
            <scope>provided </scope>
        </dependency>

2.创建配置类SwaggerConfig,进行相应的配置

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket webApiConfig(){

        return new Docket(DocumentationType.SWAGGER_2)
                .groupName("webApi")//网站上的一个名称,可随意修改
                .apiInfo(webApiInfo())
                .select()
                .paths(Predicates.not(PathSelectors.regex("/admin/.*")))
                .paths(Predicates.not(PathSelectors.regex("/error.*")))
                .build();

    }
    
    private ApiInfo webApiInfo(){

        return new ApiInfoBuilder()
                .title("网站-课程中心API文档")
                .description("本文档描述了课程中心微服务接口定义")
                .version("1.0")
                .contact(new Contact("Helen", "http://atguigu.com", "55317332@qq.com"))
                .build();
    }
}

启动项目输入图中网址,有如下结果

 

 

2.API模型

  2.1定义样例数据

  使用@ApiModelProperty注解

@ApiModelProperty(value = "创建时间", example = "2019-01-01 8:00:00")
@TableField(fill = FieldFill.INSERT)
private Date gmtCreate;

@ApiModelProperty(value = "更新时间", example = "2019-01-01 8:00:00")
@TableField(fill = FieldFill.INSERT_UPDATE)
private Date gmtModified;

 

标签:学苑,00,01,Swagger2,ApiModelProperty,private,谷粒,PathSelectors,new
来源: https://www.cnblogs.com/-wujunjie--/p/15947824.html