spring boot 中使用swagger 来自动生成接口文档
2017-10-25 14:02
906 查看
1.依赖包
2.配置类
3.controller中的方法上加上注解
4.如果一一些方法或者整个类不需要提供文档,可以在方法或者类上加上@ApiIgnore注解
<dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger-ui</artifactId> <version>2.6.1</version> </dependency> <dependency> <groupId>io.springfox</groupId> <artifactId>springfox-swagger2</artifactId> <version>2.6.1</version> </dependency>
2.配置类
package com.shinyway.workflow; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import springfox.documentation.builders.ApiInfoBuilder; import springfox.documentation.builders.PathSelectors; import springfox.documentation.builders.RequestHandlerSelectors; import springfox.documentation.service.ApiInfo; import springfox.documentation.spi.DocumentationType; import springfox.documentation.spring.web.plugins.Docket; import springfox.documentation.swagger2.annotations.EnableSwagger2; @Configuration @EnableSwagger2 public class Swagger2Configuration { @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.shinyway")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("审批平台API") .description("审批平台API") .version("1.0") .build(); } }
3.controller中的方法上加上注解
@ApiOperation(value="获取审批意见列表(html格式)", notes="通过业务号获取意见列表") @ApiImplicitParams({ @ApiImplicitParam(name = "processDefinitionKey", value = "流程定义标识", required = true, dataType = "String"), @ApiImplicitParam(name = "businessKey", value = "业务号", required = true, dataType = "String") })
4.如果一一些方法或者整个类不需要提供文档,可以在方法或者类上加上@ApiIgnore注解
相关文章推荐
- Spring Boot(九)Swagger2自动生成接口文档和Mock模拟数据
- springboot结合swagger自动生成接口文档
- spring boot rest接口自动生成文档(包含swagger)
- 使用 SpringBoot + Swagger 生成接口 API 文档
- Swagger自动接口文档生成框架————springboot整合swagger总结
- springboot+springfox+Swagger 实现项目的restful文档的自动生成
- 使用Swagger整合SpringMVC自动生成Restful接口文档
- [置顶] 使用spring-restdocs 自动生成接口文档
- SwaggerUI自动生成API文档(SwaggerUI+SpringBoot)
- Spring Boot如何让Web API自动生成文档,并解决swagger-annotations的API注解description属性废弃的问题
- 使用Spring Boot&Swagger快速构建REST API并生成优美的API文档
- IT 接口后端:足迹第十七步Restful请求格式(如何使用Swagger自动生成接口的说明文档)
- Spring Boot 使用Swagger2自动生成RESTful API文档
- Spring boot结合swagger自动生成api文档
- Spring MVC+ swagger-bootstrap-ui生成接口文档
- Swagger+Spring mvc生成Restful接口文档
- Swagger+Spring mvc生成Restful接口文档
- Swagger+Spring mvc生成Restful接口文档
- SpringBoot&Swagger构建REST API并生成API文档
- 使用 Swagger 自动生成 ASP.NET Core Web API 的文档、在线帮助测试文档(ASP.NET Core Web API 自动生成文档)