public static int[] page(int count, int sideNum, int pageNum,int everyPage) {
int pageCount = (count%everyPage==0)?count/everyPage:(count/everyPage+1); //总页数
//其实页
int startNum = 0;
//结束页
int endNum = 0;
int midpage = Math.round(sideNum / 2) +1 ;
if (sideNum > pageCount) {
endNum = pageCount;
} else {
if (pageNum <= midpage) {
endNum = sideNum;
} else {
endNum = pageNum + midpage - 1;
if (endNum > pageCount) {
endNum = pageCount;
}
}
}
if (endNum <= sideNum) {
startNum = 1;
} else {
startNum = endNum - sideNum + 1;
}
//创建数组实现数字分页
int[] a = new int[endNum - startNum +1];
for (int i = startNum; i <= endNum; i++) {
a[i-startNum] = i;
}
return a;
}
创建一个工具类 把方法贴进去即可,调用后就可以得到前台所需要的页数,循环输出即可
参数说明:
count: 当前分页的数量
sideNum: 前端分页栏一次显示多少页
pageNum: 当前页
everyPage: 每页多少条数据