1、页数=
--记录条数%每页条数==0 记录条数/每页条数
--否则 记录条数/每页条数+1
2、第N页娴熟第几条记录(记录从0开始)
--(N-1)*每页条数 = 序号 N*每页条数
1、页数=
--记录条数%每页条数==0 记录条数/每页条数
--否则 记录条数/每页条数+1
2、第N页娴熟第几条记录(记录从0开始)
--(N-1)*每页条数 =< 序号 < N*每页条数
Code
public class PageController{
private ArrayList bigList; //大的集合,外界传入
private int curentPageIndex=1; //当前页号
private int countPerpage =5; //每页条数,外界可以传
private ArrayList smallList; //小的集合,返回
private int pageCount; //页数
private int recordCount //记录条数
private int prePageIndex; //上一页序号
private int nextPageIndex; //下一页序号
private boolean firstPage; //是否是第一页
private boolean lastPage; //是否是最后一页
public void setCurrentPageIndex(int currentPageIndex)
{
this.currentPageIndex=currentPageIndex;
//上一页,下一页确定
prePageIndex=currentPageIndex-1;
nextPageIndex=currentPageIndex+1;
//是否是第一页,最后一页
if(currentPageIndex==1)
{
fistPage=true;
}
else
{
fistPage=false;
}
if(currentPageIndex==pageCount)
{
lastPage=true;
}
else
{
lastPage=false;
}
筛选工作
smallList=new ArrayList();
for(int i=(currentPageIndex-1)*countPerpage;i<currentPageIndex*countPerpage && i<recordCount;i++)
{
smallList.add(bigList.get(i));
}
}
}
public void setBigList(ArrayList bigList)
{
this.bigList=bigList;
//计算条数
recordCount=biglist.size();
//计算页数
if(recordCount%countPerpage==0)
{
pageCount=recordCount/countPerpage;
}
else
{
pageCount=recordCount/countPerpage+1;
}
}
//在ACTION中 第一页
String str=request.getParameter("PageIndex");
if(str==null)
{
str="1";
}
int currentPageIndex=Integer.parseInt(str);
PaeController pc=()PaeController request.getAttribute("pc");
if(pc==null)
{
pc=new PaeController();
StudentDao studentDao=new StudentDao();
ArrayList stus=studentDao.queryStu();
pc.setBigList(stus);
request.setAttribute("pc",pc);
}
pc.setCurrentPageIndex(currentPageIndex);
public class PageController{
private ArrayList bigList; //大的集合,外界传入
private int curentPageIndex=1; //当前页号
private int countPerpage =5; //每页条数,外界可以传
private ArrayList smallList; //小的集合,返回
private int pageCount; //页数
private int recordCount //记录条数
private int prePageIndex; //上一页序号
private int nextPageIndex; //下一页序号
private boolean firstPage; //是否是第一页
private boolean lastPage; //是否是最后一页
public void setCurrentPageIndex(int currentPageIndex)
{
this.currentPageIndex=currentPageIndex;
//上一页,下一页确定
prePageIndex=currentPageIndex-1;
nextPageIndex=currentPageIndex+1;
//是否是第一页,最后一页
if(currentPageIndex==1)
{
fistPage=true;
}
else
{
fistPage=false;
}
if(currentPageIndex==pageCount)
{
lastPage=true;
}
else
{
lastPage=false;
}
筛选工作
smallList=new ArrayList();
for(int i=(currentPageIndex-1)*countPerpage;i<currentPageIndex*countPerpage && i<recordCount;i++)
{
smallList.add(bigList.get(i));
}
}
}
public void setBigList(ArrayList bigList)
{
this.bigList=bigList;
//计算条数
recordCount=biglist.size();
//计算页数
if(recordCount%countPerpage==0)
{
pageCount=recordCount/countPerpage;
}
else
{
pageCount=recordCount/countPerpage+1;
}
}
//在ACTION中 第一页
String str=request.getParameter("PageIndex");
if(str==null)
{
str="1";
}
int currentPageIndex=Integer.parseInt(str);
PaeController pc=()PaeController request.getAttribute("pc");
if(pc==null)
{
pc=new PaeController();
StudentDao studentDao=new StudentDao();
ArrayList stus=studentDao.queryStu();
pc.setBigList(stus);
request.setAttribute("pc",pc);
}
pc.setCurrentPageIndex(currentPageIndex);
//显示页面
Code
<html:link action="/query.do?PageIndex=1">首页</html:link>
<logic:equal name="pc" property="firstPage" value="false">
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="prePageIndex">上一页</html:link>
</logic:equal>
<logic:equal name="pc" property="lastPage" value="false">
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="nextPageIndex">下一页</html:link>
</logic:equal>
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="pageCount">尾页</html:link>
<html:link action="/query.do?PageIndex=1">首页</html:link>
<logic:equal name="pc" property="firstPage" value="false">
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="prePageIndex">上一页</html:link>
</logic:equal>
<logic:equal name="pc" property="lastPage" value="false">
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="nextPageIndex">下一页</html:link>
</logic:equal>
<html:link action="/query.do?" paramId="PageIndex" paramName="pc" paramProperty="pageCount">尾页</html:link>