我想在使用 gorm 进行查询后获取用户数据
item := []models.User{}
if config.DB.First(&item, "email = ?", email).RecordNotFound() || len(item) == 0 {
c.JSON(500, gin.H{
"status": "error",
"message": "record not found"})
c.Abort()
return
}
c.JSON(200, gin.H{
"status": "success",
"data": item,
})
这是我的模型
type User struct {
gorm.Model
Stores []Store // to show that customer can have many stores
UserName string
FullName string
Email string `gorm:"unique_index"`
Password string
SocialID string
Provider string
Avatar string
Role bool `gorm:"default:0"`
HaveStore bool `gorm:"default:0"`
isActivate bool `gorm:"default:0"`
}
我只想在从gorm查询后获取用户名,如何获取?我正在使用item.Username但是,错误表明item.UserName undefined (type []models.User has no field or method UserName)
慕妹3146593
大话西游666
相关分类