private int startPage;//页码显示:起始页码
private int endPage;//页码显示:结束页码
public Page(int pageNum,int totalRecords){
this.pageNum = pageNum;
this.totalRecords = totalRecords;
//计算总页数
totalPage = (totalRecords%pageSize==0)?(totalRecords/pageSize):(totalRecords/pageSize+1);
//计算每页开始记录的索引
startIndex = (pageNum-1)*pageSize;
//计算起始页码和结束页码
if(totalPage<=9){
startPage = 1;
endPage = totalPage;
}else{
startPage = pageNum-4;
endPage = pageNum+4;
if(startPage<1){
startPage = 1;
endPage = 9;
}
if(endPage>totalPage){
endPage = totalPage;
startPage = endPage-8;
}
}
} |