type Blog struct { Id string UserId string Title string Short string Author string Tag string Content string Like string Read int } type BlogBlockParam struct { Id string Title string Tag string Short string Author string Like string Read int } funcMakeBlogBlocks(blogs []Blog)template.HTML { htmlHome := "" for _, blog := range blogs { homeParam := BlogBlockParam{}
//根据Id来返回数据 func FindMesWithId(Id string) []orm.Params { //开启调试模式,可以更好发现sql的操作是否正确 orm.Debug = true sql = "select * from mes_info where id=" + Id
var Mes []orm.Params
i, e := db.Raw(sql).Values(&Mes) fmt.Println("输出是:",i) if e != nil { fmt.Println("Raw出错") } fmt.Println("var是正常的")
return Mes }
(代码里面的print是从学长那学来的print大法,懒人不调试专用)
数据库取到的数据在对应路由的controller中直接丢给前端就好了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14
type Mes struct { Id string Intro string } ... result := models.FindMesWithId(Id) var mes [1]Mes for _, n := range result { //n["参数"],其中的参数是数据库中的列名 mes[0].Id = n["id"].(string) mes[0].Intro = n["mes_intro"].(string) } c.Data["json"] = map[string]interface{}{"mes": mes, "code": 0} c.ServeJSON()