SpringBoot集成Swagger框架

本文介绍了如何在项目中引入Swagger 2.x,包括添加依赖、创建Swagger配置类,并详细解释了@Api、@ApiOperation、@ApiImplicitParam等注解的使用。通过实例展示了如何为API文档提供标题、版本和参数描述。
摘要由CSDN通过智能技术生成

1.了解到 https://swagger.io/tools/swaggerhub

2.swagger2引入pom文件

<!--引入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>

3.创建Swagger配置类

public Docket xxxxapi(){
    return new Docket(DocumentationType.SWAGGER_2)
            .apiInfo(apiInfo()).select()
            .apis(RequestHandlerSelectors.basePackage("com.xxxx.xxxx.controller"))
            .paths(PathSelectors.any())
            .build();
}

private ApiInfo apiInfo() {
    return new ApiInfoBuilder()
            .title("xxxx")
            .version("x.x")
            .build();
}

3.Swagger中注解的说明

@Api 标注在类上面
@ApiOperation 标注在方法上
@ApiImplicitParam  请求参数的,字段,名称,是否必填,传送方式。
@ApiModel 返回参数的一个描述
@ApiModelProperty 返回对象的字段描述
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值