model 定義
type Plan struct { Id int `gorm:"primary_key"` Title string `gorm:"column:title;not null;size:128"` Start time.Time `gorm:"type:date;column:start"` End time.Time `gorm:"type:date;column:end"` Created time.Time `gorm:"autoCreateTime;column:created;type:datetime"` IsDelete int `gorm:"column:is_delete;default:1"` }
相比官網的例子,增加了type屬性
執行:
db.AutoMigrate(&Plan{})
結果:
建議把類型改為string
type Plan struct { Id int `gorm:"primary_key"` User int `gorm:"column:user;not null"` Title string `gorm:"column:title;not null;size:128"` Start string `gorm:"type:date;column:start"` End string `gorm:"type:date;column:end"` Created time.Time `gorm:"autoCreateTime;column:created;type:datetime"` IsDelete int `gorm:"column:is_delete;default:1"` }
這樣gin處理前端發過來的時間比較友好,不然會出現這樣的報錯
parsing time "2019-09-06" as "2006-01-02T15:04:05Z07:00": cannot parse "" as "T"