package Models import ( "ESG/Databases" ) type List struct{ ID int `gorm:"primary_key"` Title string `gorm:"column:title"` Cover string `gorm:"column:cover"` Content string `gorm:"column:content"` } //查询列表数据库 func (l *List) GetList() []List{ var list []List Databases.Db.Find(&list) return list } //查询单个数据库 func (l *List) GetDetails(id string) List{ Databases.Db.Where("id = ?",id).Find(&l) return *l } func (l *List) SetNews() string{ result := Databases.Db.Create(&l) if result.RowsAffected == 0{ return "发布失败" }else{ return "发布成功" } }