本帖最后由 chinafsb 于 2009-08-26 17:23:08 编辑

解决方案 »

  1.   

    在网上有用jsp实现分页的,不过它是对xml文件里的内容进行分页。
      

  2.   

    封装一个Page类,包括当前页的页数,总的页数,总的记录数,当前页的数据等信息,前台获取请求的页数作为参数传给Dao,在Dao层里面封装好一个Page对象再返回到前台显示出来public class PageBean {
        public int curPage; //当前是第几页
        public int maxPage; //一共有多少页
        public int maxRowCount; //一共有多少行
        public int rowsPerPage = 8; //每页默认多少行
        public java.util.List list;
        public PageBean() {
        }
       //3
        public void countMaxPage() { //根据总行数计算总页数
    //        //System.out.println("this.maxRowCount========"+this.maxRowCount);
            if (this.maxRowCount % this.rowsPerPage == 0) {
                this.maxPage = this.maxRowCount / this.rowsPerPage;
            } else {
                this.maxPage = this.maxRowCount / this.rowsPerPage + 1;
            }
        }    public List getList() {
            return this.list;
        }
        //1
        public void setMaxRowCount(int maxRowCount){
            this.maxRowCount=maxRowCount;
        }
        //2
        public void setList(List list){
            this.list=list;
        }
        //设置每页显示的行数
        public void setRowsPerPage(int i){
            this.rowsPerPage=i;
        }
    }
      

  3.   

    private int rowCount;//1.总记录数
    private int pageSize=15;//2.每页记录数
    private int pageCount;//3.总页数
    private int currentPage;//4.当前页数
    private boolean next;//是否能下一页
    private boolean previous;//是否能上一页

    public PageBean( String currentPage , int rowCount ){
    if( currentPage == null ){
    //如果currentPage为空,则显示是首次访问
    this.currentPage = 1;
    }else{
    this.currentPage = Integer.parseInt(currentPage);
    }
    this.rowCount = rowCount;
    //计算总页数
    this.pageCount = (int)Math.ceil(this.rowCount / (double)this.pageSize);
    //计算是否能上一页和下一页
    this.next = this.currentPage < this.pageCount;
    this.previous = this.currentPage > 1;
    }
      

  4.   

    /*
     * @description 根据PageBean分页查找部门对象 
     * @return 根据PageBean 查找部门对象的结果
     * @param null
     */
    public List<Dept> getDepts(PageBean pageBean) {
    List<Dept> list = new ArrayList<Dept>();
    String sql = "select top " +pageBean.getPageSize()+ " * from dept where dno not in " +
    "( select top " +(pageBean.getCurrentPage()-1)*pageBean.getPageSize()+ " dno from dept order by dname) order by dname";
    conn = db.getConnect();
    try {
    pstmt = conn.prepareStatement(sql);
    rs = pstmt.executeQuery();
    while (rs.next()) {
    Dept dept = new Dept();
    dept.setDno(rs.getString("dno"));
    dept.setDname(rs.getString("dname"));
    list.add(dept);
    }
    } catch (SQLException e) {
    e.printStackTrace();
    } finally {
    db.closeConnect(conn);
    }
    return list;
    }
      

  5.   

    此群是一个 java Flex 技术群,如有想在知识方面想共同进步的请加入,长期不发言者 将会被清楚群号:90551956希望大家都能带着知识和问题进来