public class Pager {
private int currentPage;
private int pageSize=3;
private int totalSize;
private int totalPage; private boolean hasFirst;
private boolean hasPrevious;
private boolean hasNext;
private boolean hasLast;
//构造函数
public Pager(int currentPage,int totalPage)
{
this.currentPage=currentPage;
this.totalPage=totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalSize() {
return totalSize;
}
public void setTotalSize(int totalSize) {
this.totalSize = totalSize;
}
public int getTotalPage() {
//计算总页数
totalPage=totalSize/pageSize;
if(totalSize%pageSize!=0)
{
totalPage++;
}
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public boolean isHasFirst() {
//判断当前页是否是第一页
if(this.currentPage==1)
return false;
return true;
}
public void setHasFirst(boolean hasFirst) {
this.hasFirst = hasFirst;
}
public boolean isHasPrevious() {
if(this.isHasFirst())
return true;
return false;
}
public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
}
public boolean isHasNext() {
//判断是否有下一页
if(this.isHasLast())
return true;
return false;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public boolean isHasLast() {
//判断当前页是否等于总页数
if(currentPage==getTotalPage())
return false;
return true;
}
public void setHasLast(boolean hasLast) {
this.hasLast = hasLast;
}
}
<ww:if test="#pager.hasFirst">
<a href="browseBook.action?currentPage=1">首页</a>
</ww:if>
<ww:if test="#pager.hasPrevious">
<a
href="browseBook.action?currentPage=<ww:property value="#pager.currentPage-1" />">上一页</a>
</ww:if>
<ww:if test="#pager.hasNext">
<a
href="browseBook.action?currentPage=<ww:property value="#pager.currentPage+1" />">下一页</a>
</ww:if>
<ww:if test="#pager.hasLast">
<a
href="browseBook.action?currentPage=<ww:property value="#pager.totalPage"/>">尾页</a>
</ww:if>
<br />
当前第
<ww:property value="#pager.currentPage" />
页,总共
<ww:property value="#pager.totalPage" />
页
</body>
</html>
在jsp页面总是显示 首页 上一页 下一页 尾页
当前页 第-1页 ,总共0页。
尤其是我将鼠标移动到尾页时,显示currentpage=0,我不知道怎么回事,麻烦各位指点。
private int currentPage;
private int pageSize=3;
private int totalSize;
private int totalPage; private boolean hasFirst;
private boolean hasPrevious;
private boolean hasNext;
private boolean hasLast;
//构造函数
public Pager(int currentPage,int totalPage)
{
this.currentPage=currentPage;
this.totalPage=totalPage;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalSize() {
return totalSize;
}
public void setTotalSize(int totalSize) {
this.totalSize = totalSize;
}
public int getTotalPage() {
//计算总页数
totalPage=totalSize/pageSize;
if(totalSize%pageSize!=0)
{
totalPage++;
}
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public boolean isHasFirst() {
//判断当前页是否是第一页
if(this.currentPage==1)
return false;
return true;
}
public void setHasFirst(boolean hasFirst) {
this.hasFirst = hasFirst;
}
public boolean isHasPrevious() {
if(this.isHasFirst())
return true;
return false;
}
public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
}
public boolean isHasNext() {
//判断是否有下一页
if(this.isHasLast())
return true;
return false;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public boolean isHasLast() {
//判断当前页是否等于总页数
if(currentPage==getTotalPage())
return false;
return true;
}
public void setHasLast(boolean hasLast) {
this.hasLast = hasLast;
}
}
<ww:if test="#pager.hasFirst">
<a href="browseBook.action?currentPage=1">首页</a>
</ww:if>
<ww:if test="#pager.hasPrevious">
<a
href="browseBook.action?currentPage=<ww:property value="#pager.currentPage-1" />">上一页</a>
</ww:if>
<ww:if test="#pager.hasNext">
<a
href="browseBook.action?currentPage=<ww:property value="#pager.currentPage+1" />">下一页</a>
</ww:if>
<ww:if test="#pager.hasLast">
<a
href="browseBook.action?currentPage=<ww:property value="#pager.totalPage"/>">尾页</a>
</ww:if>
<br />
当前第
<ww:property value="#pager.currentPage" />
页,总共
<ww:property value="#pager.totalPage" />
页
</body>
</html>
在jsp页面总是显示 首页 上一页 下一页 尾页
当前页 第-1页 ,总共0页。
尤其是我将鼠标移动到尾页时,显示currentpage=0,我不知道怎么回事,麻烦各位指点。
解决方案 »
- javaweb开发SSH整合出错HTTP Status 404 -The requested resource () is not available
- 开发service把接口先出来,再实现还是一个接口一个实现.然后先写简单的类还是核心类
- Mysql字符集问题,我设置了set character_set_results='gbk'关闭连接在打开,又是utf8了
- 怎样将struts,jsp,sql2000做的论坛发布到网上呢?我太着急了,能成功我会给好多分的,食言我就再也不来这里了。。。
- 看看struts2里这样的按钮该如何做出来的??
- 输入问题?
- 新手问题,急救
- servlet中request的问题
- java中怎么样把int型的一个数赋值给String的一个对象
- 请问各位高手,微软为JDBC提供的SQLSERER2000驱动是不是不支持JDK1.4呀?
- 求解:Resin启动错误
- hibernate 查询问题
if(this.currentPage==1)
return false;
return true;
}
把 this.currentPage==1改成 this.currentPage <=1 设置 this.currentPage=1
//判断当前页是否等于总页数
if(currentPage==getTotalPage())
return false;
return true;
}
把 currentPagecurrentPage==getTotalPage() 改成 currentPage>=getTotalPage() 设置 currentPage=getTotalPage()
有需要的朋友可以去看看