查看日志會發現表名自動加了s

在model實現以下方法即可解決
type UsUser struct {
ID int64 `gorm:"column:id" db:"column:id" json:"id" form:"id"`
CreatedTime time.Time `gorm:"column:created_time" db:"column:created_time" json:"created_time" form:"created_time"`
UpdatedTime time.Time `gorm:"column:updated_time" db:"column:updated_time" json:"updated_time" form:"updated_time"`
Username string `gorm:"column:username" db:"column:username" json:"username" form:"username"`
Password string `gorm:"column:password" db:"column:password" json:"password" form:"password"`
}
// TableName 解決gorm表明映射
func (UsUser) TableName() string {
return "us_user"
}
或者在GORM配置中設置
db, err := gorm.Open(mysql.Open(xxx.xxx.xxx.xxx)), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
SingularTable: true, // 使用單數表名
},
})
