一、在控制器中定义新的结构体
type NavJson struct {
Id int `json:"id"`
Title string `json:"title"`
}
func (NavJson) TableName() string {
return "nav"
}
二、方法
//使用Select指定返回的字段
navList := []NavJson{}
models.DB.Select("id,title").Find(&navList)
c.JSON(200, gin.H{
"result": navList,
})