package utils type PagingReq struct { CurrentIndex int `description:"当前页码" json:"_page"` PageSize int `description:"每页数据条数,如果不传,默认每页20条" json:"_page_size"` } type PagingItem struct { IsStart bool `description:"是否首页" json:"is_start"` IsEnd bool `description:"是否最后一页" json:"is_end"` PreviousIndex int `description:"上一页页码" json:"previous_index"` NextIndex int `description:"下一页页码" json:"next_index"` CurrentIndex int `description:"当前页页码" json:"current_index"` Pages int `description:"总页数" json:"pages"` Totals int `description:"总数据量" json:"totals"` PageSize int `description:"每页数据条数" json:"page_size"` } func GetPaging(currentIndex,pageSize,total int)(item *PagingItem) { if pageSize<=0 { pageSize=PageSize20 } if currentIndex<=0 { currentIndex=1 } item=new(PagingItem) item.PageSize=pageSize item.Totals=total item.CurrentIndex=currentIndex if total<=0 { item.IsStart=true item.IsEnd=true return } pages:=PageCount(total,pageSize) item.Pages=pages if pages<=1 { item.IsStart=true item.IsEnd=true item.PreviousIndex=1 item.NextIndex=1 return } if pages == currentIndex { item.IsStart=false item.IsEnd=true item.PreviousIndex=currentIndex-1 item.NextIndex=currentIndex return } if currentIndex==1 { item.IsStart=true item.IsEnd=false item.PreviousIndex=1 item.NextIndex=currentIndex+1 return } item.IsStart=false item.IsEnd=false item.PreviousIndex=currentIndex-1 item.NextIndex=currentIndex+1 return } func StartIndex2(page, pagesize int) int { if page > 1 { return (page - 1) * pagesize } return 0 } func PageCount2(count, pagesize int) int { if count%pagesize > 0 { return count/pagesize + 1 } else { return count / pagesize } }