美文网首页
通用数组分页方法

通用数组分页方法

作者: 斯嘎啦 | 来源:发表于2018-09-27 16:52 被阅读0次

该函数返回页码的startIndex, endIndex

func ArrPage(pageNumber, pageSize, totalCount int)(int,int){
    totalPage := 0
    if totalCount%pageSize == 0{
        totalPage = totalCount/pageSize
    }else{
        totalPage = totalCount/pageSize+1
    }
    fmt.Println(totalPage)

    if pageNumber < 1{
        pageNumber = 1
    }

    startIndex := (pageNumber - 1) * pageSize
    endIndex := startIndex + pageSize

    if endIndex >= totalCount{
        endIndex = totalCount
    }
   
    return startIndex, endIndex
}

相关文章

网友评论

      本文标题:通用数组分页方法

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