diff --git a/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md b/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md index 2c34e9e2..ccd5c797 100644 --- a/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md +++ b/docs/Tasktracking/2026-04-27-fix-batch-edit-shouldbindjson.md @@ -13,10 +13,11 @@ Change Type: Fix ## Changes - `web/controller/inbound.go:481`: `c.ShouldBindJSON(&request)` → `c.ShouldBind(&request)` +- `web/controller/inbound.go:477-479`: 为匿名结构体字段添加 `form` 标签,确保 form 绑定能正确映射字段名(`shouldBind` 使用 `form` 标签而非 `json` 标签进行 form 字段映射) ## Impact - `ShouldBind` 会根据 Content-Type 自动选择 form 绑定(浏览器请求)或 JSON 绑定(其他客户端),与项目其他 handler 一致 -- 向后兼容:JSON 请求依然能被正确解析 +- 向后兼容:JSON 请求依然能被正确解析(`json` 标签仍保留) - 不影响数据库、API、配置 ## Verification @@ -24,4 +25,4 @@ Change Type: Fix - `go vet ./web/controller/...` — 通过 ## Risks And Follow-Up -- 低风险,单行变更,与项目现有代码风格一致 +- 低风险,与项目现有代码风格一致(model 中所有 struct 字段均同时携带 `json` 和 `form` 标签) diff --git a/web/controller/inbound.go b/web/controller/inbound.go index 8fa7e455..cbc032b9 100644 --- a/web/controller/inbound.go +++ b/web/controller/inbound.go @@ -474,9 +474,9 @@ func (a *InboundController) delInboundClientByEmail(c *gin.Context) { // batchUpdateInboundClients updates multiple clients in an inbound with the same field changes. func (a *InboundController) batchUpdateInboundClients(c *gin.Context) { var request struct { - InboundID int `json:"inboundId"` - ClientIDs []string `json:"clientIds"` - UpdateFields string `json:"updateFields"` + InboundID int `json:"inboundId" form:"inboundId"` + ClientIDs []string `json:"clientIds" form:"clientIds"` + UpdateFields string `json:"updateFields" form:"updateFields"` } if err := c.ShouldBind(&request); err != nil { jsonMsg(c, I18nWeb(c, "pages.inbounds.toasts.inboundUpdateSuccess"), err)