Official documentation
https://doc.xiaominfo.com/docs/quick-start
Personally, it is recommended that when learning technology, it is best to refer to technical documents. If the English technical documents are difficult to read, you can refer to some Chinese documents.
1. Add dependencies
maven
<dependency>
<groupId>com.github.xiaoymin</groupId>
<artifactId>knife4j-openapi3-jakarta-spring-boot-starter</artifactId>
<version>4.0.0</version>
</dependency>
gradle
implementation "com.github.xiaoymin:knife4j-spring-boot-starter:4.0.0"
2.Write configuration file
spring:
mvc:
pathmatch:
matching-strategy: ant_path_matcher
# knife4j文档配置
knife4j:
enable: true
title: service01
description: service01描述
contact:
name: 军大的springcloud项目
url: https://www.XXXXXXX.XX
email: [email protected]
cors: true
basic:
enable: true
username: admin
password: admin
3. Fill in the notes
Among them, @Api and @ApiOperation are the key annotations
@RestController
@RequestMapping("/Service01Controller")
@Api(tags = "Service01接口测试")
public class Service01Controller {
@GetMapping("/testException")
@ApiOperation("异常测试接口")
public Result<Object> testException() {
return null;
}
}
4. Test and view
The address http://localhost:8568/doc.html is usually just add doc.html after your own port number.