美文网首页
在SpringBoot中使用Swagger

在SpringBoot中使用Swagger

作者: RageYourDream_ | 来源:发表于2017-04-28 10:53 被阅读0次
  1. 首先需要导入Swagger依赖
    <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.4.0</version> </dependency>
    <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.4.0</version> </dependency>

  2. 在使用Swagger的Controller中使用注解@EnableSwagger2

  3. 定义Swagger的Bean

@Bean
public Docket api() { return new Docket(DocumentationType.SWAGGER_2) .select() .apis(RequestHandlerSelectors.basePackage("com.elong.Controller")) .paths(PathSelectors.ant("/api/*")) .build().apiInfo(apiInfo()); }

private ApiInfo apiInfo() { ApiInfo apiInfo = new ApiInfo( "Autops REST API", "Autops平台接口", "API TOS", "OPS", "xianghui.niu", "License of API", ""); return apiInfo; }

  1. 主要的注解使用方法
  • @Api : 注解Controller,对应UI中一组API 的命名 description: 描述信息, tag: 标签
  • @ApiOperation value: api的功能介绍
  • @ApiImplicitParam(name = "id", value = "执行单号", paramType = "query")
  • @ApiResponses(value = {@ApiResponse(code = 200, message = "接口调用成功")})

相关文章

网友评论

      本文标题:在SpringBoot中使用Swagger

      本文链接:https://www.haomeiwen.com/subject/mpuozttx.html