fix(swagger): 修正Knife4j配置并补充接口注解

- 更新扫描包路径为正确包名 com.yolo.keyborad.controller
- 修正文档标题与项目名 keyborad-backend 保持一致
- 在 DemoController 添加 @Api 及 @ApiOperation 注解
This commit is contained in:
2025-10-31 19:58:50 +08:00
parent 79eee28b73
commit c552642825
3 changed files with 10 additions and 16 deletions

11
pom.xml
View File

@@ -31,13 +31,11 @@
<artifactId>mybatis-spring-boot-starter</artifactId>
<version>2.2.2</version>
</dependency>
<!-- mybatis-plus 依赖 -->
<dependency>
<groupId>com.baomidou</groupId>
<artifactId>mybatis-plus-boot-starter</artifactId>
<version>3.5.1</version>
</dependency>
<!-- redis 依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
@@ -64,7 +62,6 @@
<artifactId>knife4j-spring-boot-starter</artifactId>
<version>3.0.3</version>
</dependency>
<!-- hutool 工具-->
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
@@ -76,7 +73,6 @@
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<!-- 数据库驱动 -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
@@ -103,7 +99,6 @@
<groupId>cn.dev33</groupId>
<artifactId>sa-token-spring-boot-starter</artifactId>
<version>1.44.0</version>
<scope>compile</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
@@ -112,12 +107,6 @@
<version>4.13.2</version>
<scope>test</scope>
</dependency>
<!-- 日志依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>

View File

@@ -25,13 +25,13 @@ public class Knife4jConfig {
public Docket defaultApi2() {
return new Docket(DocumentationType.SWAGGER_2)
.apiInfo(new ApiInfoBuilder()
.title("project-backend")
.description("project-backend")
.title("keyborad-backend")
.description("keyborad-backend")
.version("1.0")
.build())
.select()
// 指定 Controller 扫描包路径
.apis(RequestHandlerSelectors.basePackage("com.yupi.project.controller"))
.apis(RequestHandlerSelectors.basePackage("com.yolo.keyborad.controller"))
.paths(PathSelectors.any())
.build();
}

View File

@@ -2,6 +2,10 @@ package com.yolo.keyborad.controller;
import com.yolo.keyborad.common.BaseResponse;
import com.yolo.keyborad.common.ResultUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
@@ -16,11 +20,12 @@ import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/demo")
@Slf4j
@CrossOrigin
@Api(tags = "测试控制器")
public class DemoController {
@GetMapping("/test")
public BaseResponse<String> hostsInfo(){
@ApiOperation("测试接口")
public BaseResponse<String> testDemo(){
return ResultUtils.success("hello world");
}
}