美文网首页
分页数据

分页数据

作者: 吴宪峰 | 来源:发表于2019-07-17 22:25 被阅读0次
    func PageUser(p int, size int) helper.Page {
    
        var user User
        var list []User
        qs := Database.Find(&user)
        var count int
        qs.Count(count)
        qs.Related(&user).Order("user_registered").Limit(size).Offset((p - 1) * size).Find(&list)
        //c, _ := strconv.Atoi(strconv.FormatInt(count, 10))
        return helper.PageUtil(count, p, size, list)
    }
    
    package helper
    
    type Page struct {
        PageNo     int
        PageSize   int
        TotalPage  int
        TotalCount int
        FirstPage  bool
        LastPage   bool
        List       interface{}
    }
    
    func PageUtil(count int, pageNo int, pageSize int, list interface{}) Page {
        tp := count / pageSize
        if count%pageSize > 0 {
            tp = count/pageSize + 1
        }
        return Page{PageNo: pageNo, PageSize: pageSize, TotalPage: tp, TotalCount: count, FirstPage: pageNo == 1, LastPage: pageNo == tp, List: list}
    }```

    相关文章

      网友评论

          本文标题:分页数据

          本文链接:https://www.haomeiwen.com/subject/barhlctx.html