谁有struts2的分页代码跪求谢谢大哥大姐们
解决方案 »
- <BEA-000421> <Uncaught Throwable in processSockets
- 通过代理访问webservices问题(急啊),高手请进
- 问问
- 关于spring中aop为何意
- select 传值问题!
- 关于DWR的配置的问题?谢谢
- 论坛的大神求助呀,jxl导入模板后导出的excel打开提示“文件错误,可能某些数字格式已丢失”什么问题呀,查了好多方法都没解决
- 有谁还记得最原始的发布命令和打包命令,在DOC界面下的
- cmp与数据库的同步!??疑惑!??
- Struts2 多语言 直接访问JSP无效的问题
- org.apache.commons的问题
- ActionForm在编译器里怎么找不到继承的类了
无非就是页面传参数(当前第几页, 每页大小)到action/controller, action/controller根据你的参数调用dao取出当前页的数据然后发送回去???
分页不是通过sql实现的吗?和struts有关系吗?
select * from table where id not
in(select id from components where
rownum<=(PAGESIZE*(CURRENTPAGE-1)))
and rownum<=PAGESIZE order by id
in(select id from table where
rownum <=(PAGESIZE*(CURRENTPAGE-1)))
and rownum <=PAGESIZE order by id
public class PageController {
private List bigList; //大的集合从外界传入
private List smallList; //小集合,每页的总记录
private int curentPageIndex = 1; //当前页号
public int countPerpage = 7; //每页记录条数
private int pageCount; //总页数(尾页页号)
private int recordCount; //总记录条数
private int prePageIndex; //上一页
private int nextPageIndex; //下一页
private boolean firstPage; //是否为第一页
private boolean lastPage; //是否为最后一页
public void setCurentPageIndex(int curentPageIndex) {//每当换页时都要运行这个函数
this.curentPageIndex = curentPageIndex;
//计算上一页,下一页
prePageIndex = curentPageIndex -1;
nextPageIndex = curentPageIndex +1;
//判断第一页,最后一页
if(curentPageIndex == 1) {
firstPage = true;
}
else {
firstPage = false;
}
if(curentPageIndex == pageCount) {
lastPage = true;
}
else {
lastPage = false;
}
smallList = new ArrayList();
for(int i=(curentPageIndex-1)*countPerpage;i<curentPageIndex*countPerpage&&i<recordCount;i++) {//i为每页记录的序号
smallList.add(bigList.get(i));//把每页的记录放入smallList中,实行分页
}
}
public List getBigList() {
return bigList;
}
public void setBigList(List bigList) {
this.bigList = bigList;
recordCount = bigList.size();//计算总条数
//计算总页数
if(recordCount%countPerpage == 0) {
pageCount = recordCount/countPerpage;
}
else {
pageCount = recordCount/countPerpage + 1;
}
}
public int getCountPerpage() {
return countPerpage;
}
public void setCountPerpage(int countPerpage) {
this.countPerpage = countPerpage;
}
public int getCurentPageIndex() {
return curentPageIndex;
}
.....后面是get set方法
然后在action里写分页代码:String str = request.getParameter("PageIndex");
if(str == null) {
str = "1";
}
int curentPageIndex = Integer.parseInt(str);
PageController pc = (PageController) request.getAttribute("pc");
if(pc == null) {
pc = new PageController();
all = sdtdao.queryByAll();
pc.setBigList(all);
request.setAttribute("pc", pc);
}
pc.setCurentPageIndex(curentPageIndex);剩下的在显示层处理就行了