【Spring-boot】引入Swagger

1, pom文件

  <swagger.version>2.7.0</swagger.version>
  <!--其他版本EnableSwagger2注解找不到,可能是个例,待验证。-->
 -------------------------------------------------              
  <!--swagger start-->
  <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger2</artifactId>
      <version>${swagger.version}</version>
  </dependency>
  <dependency>
      <groupId>io.springfox</groupId>
      <artifactId>springfox-swagger-ui</artifactId>
      <version>${swagger.version}</version>
  </dependency>
  <!--swagger end-->

2,swagger配置

@Configuration
@EnableSwagger2
public class SwaggerConfig {

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("包路径"))
                .paths(PathSelectors.any())
                .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("标题")
                .description("描述")
                .termsOfServiceUrl("地址")
                .contact(new Contact("联系人", "", ""))
                .version("1.0")
                .build();
    }

}

3,使用
* 忽略类或方法
@ApiIgnore
* 类注释
@Api(tags = “账单管理”, description = “账单管理API”)
* 方法注释
@ApiOperation(value = “获取最新已出账单”, notes = “获取最新已出账单”)
@ApiImplicitParam(name = “id”, value = “用户账单id”, required = true, dataType = “Long”, paramType = “path”)
paramType类型:path, query, body, header, form
@ApiImplicitParams用于组织多个ApiImplicitParam
如:
> @ApiImplicitParams({
@ApiImplicitParam(name = “size”, value = “每页数量”, dataType = “Long”, paramType = “query”),
@ApiImplicitParam(name = “current”, value = “页码”, dataType = “Long”, paramType = “query”)
})

参考:
https://blog.csdn.net/itguangit/article/details/78978296
http://blog.didispace.com/springbootswagger2/

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值