通用数组分页方法

2018-09-27  本文已影响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
}

上一篇 下一篇

猜你喜欢

热点阅读