参考链接:狂神的Swagger笔记
- 号称世界上最流行的API框架
- Restful Api 文档在线自动生成器 => API 文档 与API 定义同步更新
- 直接运行,在线测试API
- 支持多种语言 (如:Java,PHP等)
- 官网:swagger
SpringBoot集成Swagger 添加maven依赖
<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>要求:jdk 1.8 + 否则swagger2无法运行 要使用Swagger,我们需要编写一个配置类-SwaggerConfig来配置 Swagger
package com.yf.exam.config;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import springfox.documentation.service.ApiInfo;import springfox.documentation.service.Contact;import springfox.documentation.spi.DocumentationType;import springfox.documentation.spring.web.plugins.Docket;import springfox.documentation.swagger2.annotations.EnableSwagger2;import java.util.ArrayList;@Configuration@EnableSwagger2public class SwaggerConfig { //配置了swagger的Docket 的 bean 实例 @Bean public Docket docket(){ return new Docket(DocumentationType.SWAGGER_2) .apiInfo(apiInfo()); } //配置 swagger 信息 = apiInfo private ApiInfo apiInfo(){ //作者信息 Contact contact = new Contact("潇七", "https://.github.xiaoymin</groupId> <artifactId>knife4j-spring-boot-starter</artifactId> <!--在引用时请在maven中央仓库搜索最新版本号--> <version>2.0.4</version> </dependency>-访问测试 :http://localhost:8080/doc.html ,可以看到knife4j的界面;
离线文档导出
Knife4j提供导出4种格式的离线文档(Html\Markdown\Word\Pdf)
到此这篇关于springboot集成swagger以及knife4j的增强的文章就介绍到这了,更多相关springboot集成swagger内容请搜索以前的文章或继续浏览下面的相关文章希望大家以后多多支持!