From 7b6026950a9001802d2e032c22ed5d9d2320c3e8 Mon Sep 17 00:00:00 2001 From: maguodong Date: Sat, 28 Mar 2026 14:37:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor(database):=20=E6=9B=B4=E6=96=B0?= =?UTF-8?q?=E5=9F=BA=E7=A1=80=E6=A8=A1=E5=9E=8B=E7=9A=84=E6=97=B6=E9=97=B4?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E9=85=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 修改 CreateTime 字段的 JSON 标签从 created_at 到 create_time - 修改 UpdateTime 字段的 JSON 标签从 updated_at 到 update_time - 添加 autoCreateTime 和 autoUpdateTime GORM 标签实现自动时间戳 - 移除手动时间设置的相关注释 - 统一字段标签格式为 common 格式 --- database/model/base.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/database/model/base.go b/database/model/base.go index 1ac7194..5df2ccd 100644 --- a/database/model/base.go +++ b/database/model/base.go @@ -8,9 +8,9 @@ import ( // BaseModel 基础模型,包含自定义的创建时间和更新时间 type BaseModel struct { - Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;common:主键ID"` // 主键 ID - CreateTime time.Time `gorm:"column:create_time;type:datetime;not null" json:"created_at"` // 创建时间 - UpdateTime time.Time `gorm:"column:update_time;type:datetime;not null" json:"updated_at"` // 更新时间 + Id int `json:"id" gorm:"column:id;primaryKey;autoIncrement;common:主键ID"` // 主键 ID + CreateTime time.Time `json:"create_time" gorm:"column:create_time;type:datetime;autoCreateTime;common:创建时间"` + UpdateTime time.Time `json:"update_time" gorm:"column:update_time;type:datetime;autoUpdateTime;common:更新时间"` } // BeforeCreate 创建前自动设置时间