controller包下:
func (c *Area)List() {
id, _ := c.GetInt("parent_id")
//查询
where := make(map[string]interface{})
where["parent_id"] = id
//初始化
mod := admin.NewAreaService()
//查询
page, _ := c.GetInt("page")
data, err := model.GetAll(where, []string{}, "id ASC", page, 999)
if err != nil {
fmt.Println(err.Error())
c.Error(err.Error())
return
}
c.Data["data"] = data
//扩展查询
ext := admin.NewAreaExtService()
data_ext, err := ext.GetAll(where, []string{}, "id ASC,ext_id ASC", page, 999)
if err != nil {
c.Error(err.Error())
return
}
c.Data["data_ext"] = data_ext
c.Data["title"] = "地区-列表"
c.TplName = "admin/areast.html"
}
model包下:
func (c *Area) GetAll(q map[string]interface{}, fields []string, orderBy string, page int, limit int) (*db.Paginator, error) {
session := db.Filter(q)
count, err := session.Count(c)
if err != nil {
fmt.Println(err)
return nil,fox.NewError( err.Error())
}
Query := db.Pagination(int(count), page, limit)
if count == 0 {
return Query, nil
}
session = db.Filter(q)
if orderBy != "" {
session.OrderBy(orderBy)
}
session.Limit(limit, Query.Offset)
if len(fields) == 0 {
session.AllCols()
}
data := c.newMakeDataArr()
err = session.Find(&data)
if err != nil {
fmt.Println(err)
return nil,fox.NewError( err.Error())
}
Query.Data = make([]interface{}, len(data))
for y, x := range data {
Query.Data[y] = x
}
return Query, nil
}
编译错误:
F:\jgn02\src\blog>go build main.go
# blog/controllers/admin
controllers\admin\area.go:26:15: undefined: model
有疑问加站长微信联系(非本文作者))