谁有struts2的分页代码跪求谢谢大哥大姐们

解决方案 »

  1.   

    大哥,分页我觉得和struts根本粘不上边. 你用jsp, struts1, 还是struts2, 分页还不都是那么搞的?
    无非就是页面传参数(当前第几页, 每页大小)到action/controller, action/controller根据你的参数调用dao取出当前页的数据然后发送回去???
      

  2.   


    分页不是通过sql实现的吗?和struts有关系吗?
    select * from table where id not 
    in(select id from components where                
    rownum<=(PAGESIZE*(CURRENTPAGE-1))) 
    and rownum<=PAGESIZE order by id
      

  3.   

    select * from table where id not 
    in(select id from table where                
    rownum <=(PAGESIZE*(CURRENTPAGE-1))) 
    and rownum <=PAGESIZE order by id 
      

  4.   

    这个写法是oracle的,具体怎么写,上网去搜索,网上有的是
      

  5.   

    http://blog.csdn.net/yongtree/archive/2008/11/09/3260738.aspx
      

  6.   

    先写一个分页类PageController,代码如下:
    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);剩下的在显示层处理就行了