package model // Book 结构体定义 type Book struct { // grom:"column:isbn;", 具体文档: https://gorm.io/docs/models.html#Fields-Tags IsBN uint `json:"isbn" gorm:"primaryKey;column:isbn"` BookSpec } type BookSpec struct { Title string `json:"title" gorm:"column:title;type:varchar(200)"` Author string `json:"author" gorm:"column:author;type:varchar(200);index"` Price float64 `json:"price" gorm:"column:price"` // bool false // nil 是零值, false IsSale *bool `json:"is_sale" gorm:"column:is_sale"` } // 定义该对象映射到数据里 表的名称 func (t *Book) TableName() string { return "books" }