我正在嘗試在 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
提交
取消