try 使用GORM方法Find获取数据库表的值,但它没有返回所有字段的值. 表 struct 是,
CREATE TABLE `company` (
`id` varchar(36) NOT NULL,
`createdAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`updatedAt` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`name` varchar(255) NOT NULL,
`newId` varchar(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
在Company.Go中,我们将公司 struct 定义为:
package entities
import "time"
type Company struct {
Id string `json:"id" gorm:"column:id;primaryKey"`
CreatedAt time.Time `json:"createdAt" gorm:"column:createdAt"`
UpdatedAt time.Time `json:"updatedAt" gorm:"column:updatedAt"`
Name string `json:"name" gorm:"column:name"`
NewId string `json:"newId" gorm:"column:newId"`
}
在控制器Companies.Go中,使用以下代码获取数据,
var companys []entities.Company
result := db.Find(&companys)
c.JSON(http.StatusOK, &result)
在postman 中,它只返回字段name和id的值.其余字段的值为空.这可能是什么问题呢?
我try 使用GORM的Find方法获取所有字段,但它只给出了两个字段