一:Paging类
package com.wmampr.common;
@SuppressWarnings("unused")
public class Paging {
private int currentPage;//当前页
private int pageSize = 5;//每页显示多少条
private int totalSize;//总的记录数
private int totalPage;//总的页数
private boolean hasFirst;//首页
private boolean hasPrevious;//判断有无上一页
private boolean hasNext;//判断有无下一页
private boolean hasLast;//最有一页
public Paging(){
}
public Paging(int currentPage){
this.currentPage = currentPage;
}
public Paging(int currentPage,int totalSize){ //有当前页能判断有无上下页 有总记录数能判断一共有多少页
this.currentPage = currentPage;
this.totalSize = totalSize;
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public boolean isHasFirst() {//是否是首页
if(currentPage == 1)
return false;
return true;
}
public void setHasFirst(boolean hasFirst) {
this.hasFirst = hasFirst;
}
public boolean isHasLast() {//是否是最后一页
if(currentPage == getTotalPage()||getTotalPage()==0)
return false;
return true;
}
public void setHasLast(boolean hasLast) {
this.hasLast = hasLast;
}
public boolean isHasNext() {//有无下一页
if(isHasLast())
return true;
return false;
}
public void setHasNext(boolean hasNext) {
this.hasNext = hasNext;
}
public boolean isHasPrevious() {//有无前一页
if(isHasFirst())
return true;
return false;
}
public void setHasPrevious(boolean hasPrevious) {
this.hasPrevious = hasPrevious;
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
}
public int getTotalPage() { //一共多少页
totalPage = totalSize / pageSize;
if(totalSize % pageSize != 0)
totalPage++;
return totalPage;
}
public void setTotalPage(int totalPage) {
this.totalPage = totalPage;
}
public int getTotalSize() {
return totalSize;
}
public void setTotalSize(int totalSize) {
this.totalSize = totalSize;
}
}
二:Action类
private int currentPage=1;
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
}
public String getQy(){//查询所有招聘企业
int countRow=qycxService.getCountRow();
Paging page=new Paging(currentPage,countRow);
if(currentPage>page.getTotalPage()){
currentPage=page.getTotalPage();
}
if(0==page.getTotalPage()){
currentPage=1;
}
page.setCurrentPage(currentPage);
List qyList=qycxService.getQy(currentPage,page.getPageSize());
Map request=(Map)ActionContext.getContext().get("request");
request.put("qyList",qyList);
request.put("page",page);
return SUCCESS;
}
三:页面
<ww:set name="page" value="#request.page"/>
<div align="right">
<ww:if test="#page.hasFirst">
<a href="MCgetTodayPrice.action?currentPage=1">首页</a>
</ww:if>
<ww:if test="#page.hasPrevious">
<a href="MCgetTodayPrice.action?currentPage=<ww:property value="#page.currentPage-1"/>">上一页</a>
</ww:if>
<ww:if test="#page.hasNext">
<a href="MCgetTodayPrice.action?currentPage=<ww:property value="#page.currentPage+1"/>">下一页</a>
</ww:if>
<ww:if test="#page.hasLast">
<a href="MCgetTodayPrice.action?currentPage=<ww:property value="#page.totalPage"/>">尾页</a>
</ww:if>
<br/>
当前第<FONT color="red"><ww:property value="#page.currentPage"/></FONT>页,
总共<FONT color="red"><ww:property value="#page.totalPage"/></FONT>页.
四:sql语句
SELECT * FROM
(
SELECT A.*, ROWNUM RN FROM (SELECT * FROM product where BIGCLASSNAME=#bigclassname# order by updatetime desc) A
WHERE ROWNUM <=#currentPage#*#pageSize#)
WHERE RN >(#currentPage#-1)*#pageSize#