From 883f67c5484e6bc8bda1ef5e6f38d4231aaa790b Mon Sep 17 00:00:00 2001 From: lixuhuilll <676824363@qq.com> Date: Sat, 2 Mar 2024 16:55:36 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8@BindParam=E4=BB=A5=E5=90=8C?= =?UTF-8?q?=E6=97=B6=E9=80=82=E9=85=8D=E9=A9=BC=E5=B3=B0=E5=92=8CSnakeCase?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../backend/controller/CopilotController.kt | 13 ------ .../request/copilot/CopilotQueriesRequest.kt | 40 +++---------------- 2 files changed, 6 insertions(+), 47 deletions(-) diff --git a/src/main/kotlin/plus/maa/backend/controller/CopilotController.kt b/src/main/kotlin/plus/maa/backend/controller/CopilotController.kt index f50cfc5e..6e0b88e4 100644 --- a/src/main/kotlin/plus/maa/backend/controller/CopilotController.kt +++ b/src/main/kotlin/plus/maa/backend/controller/CopilotController.kt @@ -74,19 +74,6 @@ class CopilotController( fun queriesCopilot( @ParameterObject parsed: @Valid CopilotQueriesRequest ): MaaResult { - // FIXME 请求对下划线的处理存在问题,需要更正 - if (parsed.copilotIds == null) { - parsed.copilotIds = parsed.copilot_ids - } - if (parsed.levelKeyword == null) { - parsed.levelKeyword = parsed.level_keyword - } - if (parsed.orderBy == null) { - parsed.orderBy = parsed.order_by - } - if (parsed.uploaderId == null) { - parsed.uploaderId = parsed.uploader_id - } // 三秒防抖,缓解前端重复请求问题 response.setHeader(HttpHeaders.CACHE_CONTROL, "private, max-age=3, must-revalidate") return success(copilotService.queriesCopilot(helper.userId, parsed)) diff --git a/src/main/kotlin/plus/maa/backend/controller/request/copilot/CopilotQueriesRequest.kt b/src/main/kotlin/plus/maa/backend/controller/request/copilot/CopilotQueriesRequest.kt index 2258e79d..4c6b3d5e 100644 --- a/src/main/kotlin/plus/maa/backend/controller/request/copilot/CopilotQueriesRequest.kt +++ b/src/main/kotlin/plus/maa/backend/controller/request/copilot/CopilotQueriesRequest.kt @@ -1,6 +1,7 @@ package plus.maa.backend.controller.request.copilot import jakarta.validation.constraints.Max +import org.springframework.web.bind.annotation.BindParam /** * @author LoMu @@ -9,42 +10,13 @@ import jakarta.validation.constraints.Max data class CopilotQueriesRequest( val page: Int = 0, val limit: @Max(value = 50, message = "单页大小不得超过50") Int = 10, - var levelKeyword: String? = null, - val level_keyword: String? = null, + @BindParam("level_keyword") var levelKeyword: String? = null, val operator: String? = null, val content: String? = null, val document: String? = null, - var uploaderId: String? = null, - val uploader_id: String? = null, + @BindParam("uploader_id") var uploaderId: String? = null, val desc: Boolean = true, - var orderBy: String? = null, - val order_by: String? = null, + @BindParam("order_by") var orderBy: String? = null, val language: String? = null, - var copilotIds: List? = null, - val copilot_ids: List? = null -) { - -// /* -// * 这里为了正确接收前端的下划线风格,手动写了三个 setter 用于起别名 -// * 因为 Get 请求传入的参数不是 JSON,所以没办法使用 Jackson 的注解直接实现别名 -// * 添加 @JsonAlias 和 @JsonIgnore 注解只是为了保障 Swagger 的文档正确显示 -// * (吐槽一下,同样是Get请求,怎么CommentsQueries是驼峰命名,到了CopilotQueries就成了下划线命名) -// */ -// @JsonIgnore -// @Suppress("unused") -// fun setLevel_keyword(levelKeyword: String?) { -// this.levelKeyword = levelKeyword -// } -// -// @JsonIgnore -// @Suppress("unused") -// fun setUploader_id(uploaderId: String?) { -// this.uploaderId = uploaderId -// } -// -// @JsonIgnore -// @Suppress("unused") -// fun setCopilot_ids(copilotIds: List?) { -// this.copilotIds = copilotIds -// } -} + @BindParam("copilot_ids") var copilotIds: List? = null, +)