beego数据库orm操作数据表返回数组
1.0 数据表模型(mode)
func GetMyads(zoneid string) ([]orm.ParamsList, error) { tidNum, err := strconv.ParseInt(zoneid, 10, 32) if err != nil { return nil, err } //查询数据表 o := orm.NewOrm() var lsits []orm.ParamsList num, err := o.Raw("SELECT * FROM `oepre_myads` WHERE `zoneid` = ? LIMIT 0, 30", tidNum).ValuesList(&lsits) if err == nil && num > 0 { } return lsits, nil }
2.0 控制器(controller)
func (this *MainController) Get() { this.Data["IsHome"] = true this.Data["Website"] = "s.me" this.Data["Email"] = "304030196@qq.com" this.TplNames = "templets/default/index.tpl" var datalist []orm.ParamsList datalist, err := models.GetMyads("2") if err != nil { beego.Error(err) } fmt.Printf("-----------------------------%d", datalist) }
3.0 会返回一个数组