我有一个用户模型,目前只有一行。我想指望整个用户表中的行数,这里是我的代码:计数返回错误结果
var count int64
db.Model(&models.User{}).Count(count)
fmt.Println(count)
我期待但打印。 什么是使用gorm打印表格中的行数的正确方法?
更新:我的用户模型:
package models
import "github.com/jinzhu/gorm"
type User struct {
gorm.Model
Name string
Password string
Admin bool
}
我们不知道'db.Model','models.User'和'Count'是他们做什么或他们做了什么。请提供[最小,完整和可验证示例](https://stackoverflow.com/help/mcve)。 – Marc