gorm框架表名自动加s问题
查看日志会发现表名自动加了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, // 使用单数表名
},
})

浙公网安备 33010602011771号