springboot 使用 Swagger2 整合api文档
2020-06-06 05:55
344 查看
1.在父工程的pom.xml中引入相关的Swagger2依赖
<!-- swagger2 配置 --> <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> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>swagger-bootstrap-ui</artifactId> <version>1.6</version> </dependency>
2.编写Swagger2类
@Configuration @EnableSwagger2 public class Swagger2 { //访问地址(原路径):http:localhost:8088/swagger-ui.html //修饰后的路径:http:localhost:8088/doc.html @Bean public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()) .select() .apis(RequestHandlerSelectors.basePackage("com.lzx.controller")) .paths(PathSelectors.any()) .build(); } private ApiInfo apiInfo() { return new ApiInfoBuilder() .title("天天吃货 电商平台") .contact(new Contact("lzx", "www.baidu.com", "xxxxxxxxx@qq.com")) .description("专门为天天吃货提供的文档API") .version("1.0.1") .termsOfServiceUrl("www.baidu.com") .build(); } }
3.运行访问
访问地址(原路径):http:localhost:8088/swagger-ui.html
修饰后的路径:http:localhost:8088/doc.html(ui修饰后的界面)
4.在一些方法或属性中添加一些中文注释让别人看得懂.
4-1@ApiIgnore标明Api文档中隐藏该接口(在类名上注释)
4-2@Api注释相应名称(在类名上注释)
4-3@@ApiModel(在实体来上注释)
4-4@ApiModelProperty(在实体类上的属性注释)
4-4@ApiParam(在方法属性上的注释)
5.Swgger2也提供了在线请求调试
相关文章推荐
- Spring Boot 2.0.0.M7 中使用Swagger2构建RESTful API文档
- springBoot 整合 swagger2 构建RESTful API文档
- Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档
- Spring boot 使用Swagger2构建RESTful API文档
- SpringBoot中使用Swagger2构建RESTful API文档
- Spring Boot 2.x基础教程:使用Swagger2构建强大的API文档
- Springboot中使用Swagger2构建RESTful API文档
- Spring Boot中使用Swagger2构建API文档
- SpringBoot入门实践(八)-使用Swagger2构建强大的API文档
- 在spring-boot中使用swagger2来构建RESTful API文档
- SpringBoot开发详解(八) -- 使用Swagger2构建API文档
- Spring Boot (十五): 优雅的使用 API 文档工具 Swagger2
- SpringBoot中如何使用Swagger2快速构建API文档?
- Spring Boot中使用Swagger2构建强大的RESTful API文档
- Spring Boot中使用Swagger2构建强大的RESTful API文档
- Spring Boot中使用Swagger2构建强大的RESTful API文档
- Spring Boot中使用Swagger2构建强大的RESTful API文档
- Spring Boot中使用Swagger2构建强大的RESTful API文档
- 基于Spring Boot, Spring Security 整合Swagger UI实现在线API文档
- Spring Boot中使用Swagger2构建强大的RESTful API文档