jsp的分页类

以下是我写的一个类,是用来分页的,目标是为了根据创建新对象时传进去的参数,得到自己想要的值。
可是我写了一半不知道怎么写了。就差最一个页码号的集合了,有会的帮我写一下了。还有我想知道jsp的菜单联动是怎么做出来的!

package com.snow.util;

import java.util.LinkedList;

public class PageBean {
/* sql开始位置 /
private int sqlStart;
/
sql结束位置 */
private int sqlEnd;

/* 列表的大小 */
private int pageSize;
/* 当前页号 是索引号 */
private int pageIndex;
/* 第一页 */
private int firstIndex = 0;
/* 最后一页 */
private int lastIndex;
/* 下一页 */
private int nextIndex;
/* 上一页 */
private int previousIndex;
/* 页号的集合 */
private LinkedList<Integer> listIndex = null;
/* 页号的长度 */
private int listCount;
/* 距两列表两边的距离 */
private int listMargin;
/* 总工多少页 */
private int countPage;
/* 总工有多少条记录 */
private int count;

public PageBean(int pageSize, int pageIndex, int count) {
    this.pageSize = pageSize;
    this.listCount = 5;
    this.listMargin = 3;
    this.count = count;
    this.getCountPage();
    if (pageIndex > 0 && pageIndex < (this.countPage)) {
        this.pageIndex = pageIndex;
    } else {
        this.pageIndex = 0;
    }

}

/* sql开始位置 */
public int getSqlStart() {
    this.sqlStart = this.pageIndex * this.pageSize;
    return sqlStart;
}

/* sql结束位置 */
public int getSqlEnd() {
    return sqlEnd;
}

/* 列表的大小 */
public int getPageSize() {
    return pageSize;
}

/* 当前页号 是索引号 */
public int getPageIndex() {
    return pageIndex;
}

/* 第一页 */
public int getFirstIndex() {
    this.firstIndex = 0;
    return firstIndex;
}

/* 最后一页 */
public int getLastIndex() {
    if (this.countPage > 0) {
        this.lastIndex = this.countPage - 1;
    } else {
        this.lastIndex = 0;
    }
    return lastIndex;
}

/* 下一页 */
public int getNextIndex() {
    this.nextIndex = this.pageIndex + 1;
    if (this.nextIndex >= this.countPage) {
        this.nextIndex = this.countPage - 1;
    }
    return nextIndex;
}

/* 上一页 */
public int getPreviousIndex() {
    this.previousIndex = this.pageIndex - 1;
    if (this.previousIndex < 0) {
        this.previousIndex = 0;
    }
    return previousIndex;
}

/* 页号的集合 */
[color=red]public LinkedList<Integer> getListIndex() {[/color]      int currPageNumber = this.pageIndex + 1;
    int pageNumbers = this.countPage;
    int start=this.listMargin;
    int end=pageNumbers-this.listMargin;
    int logo=-19;
    if((currPageNumber>start)&& (currPageNumber<end)){
        if((currPageNumber-this.listMargin)==1){
            logo=2;
        }else{
            logo=currPageNumber-this.listMargin+1;
        }
    }else{
        if(currPageNumber<=start){
            logo=1;
        }else {
            if((pageNumbers-currPageNumber)==0){
                logo=pageNumbers-this.listCount+1;
            }else{
                logo=currPageNumber-this.listCount-1;
            }
        }
    }
    System.out.println("start:"+String.valueOf(start));
    System.out.println("end:"+String.valueOf(end));
    System.out.println("logo:"+String.valueOf(logo));
    System.out.println("分页长度:" + String.valueOf(this.listCount));
    System.out.println("两边距离" + String.valueOf(this.listMargin));
    System.out.println("当前的页号:" + String.valueOf(currPageNumber));
    System.out.println("总页数:" + String.valueOf(pageNumbers));
    return listIndex;
}

/* 页号的长度 */
public int getListCount() {
    return listCount;
}

/* 总工多少页 */
public int getCountPage() {
    if ((this.count % this.pageSize) == 0) {
        this.countPage = this.count / this.pageSize;
    } else {
        this.countPage = this.count / this.pageSize;
        this.countPage = this.countPage + 1;
    }
    return countPage;
}

public int getListMargin() {
    return listMargin;
}

public void setListMargin(int listMargin) {
    if (this.listMargin <= this.listCount) {
        this.listMargin = this.listCount;
    }
    this.listMargin = listMargin;
}

}

查看全部
skysnowking
skysnowking
2009/11/28 16:17
  • struts
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

0个回复