我正在尝试在 Go 中制作一个简单的博客 API。这是我的结构type Blog struct { Id int `gorm:"primary key" json:"id"` Author string `gorm:"type:varchar(100);not null" json:"author"` Title string `gorm:"type:varchar(1000);not null" json:"title"` Body string `gorm:"size:1000;not null" json:"body"`}除 get all 方法外,所有其他 create get 方法均有效func (b *Blog) GetAll(db *gorm.DB) (*[]Blog, error){ var blogs []Blog records := db.Find(&blogs) if records.Error != nil{ return &[]Blog{}, records.Error } return &blogs, nil}此方法执行此查询,如调试输出中所示SELECT * FROM "blogs" WHERE "blogs"."id" = 0 ORDER BY "blogs"."id" LIMIT 1这显然不会返回任何东西我曾尝试在文档上查找,但文档建议我只这样做......并且stackoverflow上没有人遇到过这个问题
添加回答
举报
0/150
提交
取消