springboot 引入 knife4j

官方文档

https://doc.xiaominfo.com/docs/quick-start
个人建议技术学习最好参考技术文档,若是英文的技术文档难以阅读,可以参考部分的中文文档。

1.添加依赖

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.编写配置文件

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.填写注解

其中@Api 和 @ApiOperation 是关键注解

@RestController
@RequestMapping("/Service01Controller")
@Api(tags = "Service01接口测试")
public class Service01Controller {
    
    

    @GetMapping("/testException")
    @ApiOperation("异常测试接口")
    public Result<Object> testException() {
    
    
        return null;
    }
}

4.测试查看

http://localhost:8568/doc.html 这个地址一般都是在你自己的端口号后加上doc.html就可以了在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_42581660/article/details/129383029