knife4j是为Java MVC框架集成Swagger生成Api文档的增强解决方案,
前身是swagger-bootstrap-ui
,前身swagger-bootstrap-ui
是一个纯swagger-ui
的ui
皮肤项目,取名knife4j是希望它能像一把匕首一样小巧,轻量,并且功能强悍!其底层是对Springfox的封装,使用方式也和Springfox一致,只是对接口文档UI进行了优化。
官网:Knife4j · 集Swagger2及OpenAPI3为一体的增强解决方案. | Knife4j
1、导入相关包
<!--官网建议:Spring Boot 版本建议 2.4.0~3.0.0之间-->
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi2-spring-boot-starter</artifactId>
<version>${knife4j-spring.version}</version>
</dependency>
2、在application.yml配置文件中,添加knife4j相关的配置信息
# Knife4j文档
knife4j:
enable: true
basic:
enable: false
username: admin
password: admin
openapi:
title: 在线文档
description: "Knife4j文档"
# aaa"
email: xiaoymin@foxmail.com
concat: xxx
url: https://www.xxxx.com/
version: v4.0
license: Apache 2.0
group:
test1:
group-name: 分组名称
api-rule: package
api-rule-resources:
- com.xxx.xx.controller
3、在controller层添加相应的文档注释
@Api(tags = "首页模块")
@ApiOperation(value = "首页信息")
@Api(tags = "首页模块")
@RestController
public class IndexController {
@ApiOperation(value = "首页信息")
@GetMapping
public String index(){
return "security chapter 02 前后分离";
}
}