Swagger3.0基础使用

Swagger3.0

旧版本依赖删除,增加新依赖

<dependency>
    <groupId>io.springfox</groupId>
    <artifactId>springfox-boot-starter</artifactId>
    <version>3.0.0</version>
</dependency>

配置类

@Configuration
@EnableOpenApi
public class Swagger3Config {
}

这时候已经可以看看效果了(网址和之前不一样了)

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

具体配置类

@Configuration
@EnableOpenApi
public class Swagger3Config {
    @Bean
    public Docket docket() {
        return new Docket(DocumentationType.OAS_30)
                .apiInfo(apiInfo());
    }

    /**
     * 页面基础信息
     */
    private ApiInfo apiInfo() {
        // 作者信息
        Contact contact = new Contact("dijianze", "https://www.baidu.com", "123456@qq.com");
        return new ApiInfo(
                "德利的接口文档",
                "项目描述",
                "1.0",
                "https://www.baidu.com/",
                contact,
                "Apache 2.0",
                "http://www.apache.org/licenses/LICENSE-2.0",
                new ArrayList());
    }
}

实体类注解

@ApiModel("用户实体")
public class User implements Serializable {
    private String id;
    @ApiModelProperty("姓名")
    private String name;
    @ApiModelProperty("手机号")
    private String phone;
}

常用注解

Swagger注解简单说明
@Api(tags = “xxx模块说明”)作用在模块类上
@ApiOperation(“xxx接口说明”)作用在接口方法上
@ApiModel(“xxxPOJO说明”)作用在模型类上:如VO、BO
@ApiModelProperty(value = “xxx属性说明”,hidden = true)作用在类方法和属性上,hidden设置为true可以隐藏该属性
@ApiParam(“xxx参数说明”)作用在参数、方法和字段上,类似@ApiModelProperty

版权声明:本文为qq_41690324原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。