由于每次要将对应页数所需要的数据在jsp或者html等文件中显示出来,所以要将这些数据封装在一个javabean中
,后台都将查询到的数据导入到对应的javabean对象实例中,我们再将该对象存入request作用域,html或者jsp页面
从域中获取所需要的数据
import java.util.List;
public class LepPage<T> {
    /**
     * 如果指定的分页大小小于等于0,则义默认分页为20条数据
     */
    public static final int DEFAULT_ROW_SIZE = 20;
    /**
     * 如果指定的分页页码小于等于0,则默认为第一页。
     */
    public static final int DEFAULT_PAGE_NUM = 1;
    private int pageNo=DEFAULT_PAGE_NUM; // 当前页码
    private int pageSize=DEFAULT_ROW_SIZE; // 页面大小
    private int totalCount=-1; // 总记录数
    private int totalPage=-1; // 总页数
    private int startIndex; // 分页开始位置
    private int endIndex; // 分页结束位置
    private List<T> results; // 返回的结果集
    /*
     * 是否手动设置过总记录数<br/>
     * 如果手动设置过,则不自动去计算数据总数。否则,将对SQL语句包装成COUNT语句去查询总记录数
     */
    private boolean alreadySetTotolRecode = false;
    /*
     * 计算总页数
     */
    private void calculateTotalPage() {
        this.alreadySetTotolRecode = true;
        if ( this.totalCount < 0 ) {
            this.totalCount = 0;
        }
        if ( this.totalCount % this.pageSize == 0 ) {
            this.totalPage = this.totalCount / this.pageSize;
        } else {
            this.totalPage = this.totalCount / this.pageSize + 1;
        }
    }
    /**
     * 该方法不推荐使用,使用{@code Page(int PageNo, int pageSize)}进行替换
     */
    public LepPage() {
        super();
    }
    private void calculatorPageNo() {
        this.startIndex = pageNo > 0 ? ((pageNo - 1) * pageSize) : 0;
        this.endIndex = pageNo * pageSize;
    }
    /**
     * 构造一个Page对象
     * @param pageNo 当前页码
     * @param pageSize 页面大小
     */
    public LepPage(int pageNo, int pageSize) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        calculatorPageNo();
    }
    public int getPageNo() {
        return pageNo;
    }
    public void setPageNo(int PageNo) {
        if ( PageNo <= 0 ) {
            this.pageNo = DEFAULT_PAGE_NUM;
        }
        this.pageNo = PageNo;
        calculatorPageNo();
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        if ( pageSize <= 0 ) {
            this.pageSize = DEFAULT_ROW_SIZE;
        }
        this.pageSize = pageSize;
        calculatorPageNo();
    }
    public int getTotalCount() {
        return totalCount;
    }
    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
        // 去计算总页数
        calculateTotalPage();
    }
    public int getTotalPage() {
        return totalPage;
    }
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public int getStartIndex() {
        return startIndex;
    }
    public void setStartIndex(int startIndex) {
        this.startIndex = startIndex;
    }
    public int getEndIndex() {
        return endIndex;
    }
    public void setEndIndex(int endIndex) {
        this.endIndex = endIndex;
    }
    public List<T> getResults() {
        return results;
    }
    public void setResults(List<T> results) {
        this.results = results;
    }
    public boolean isAlreadySetTotolRecode() {
        return alreadySetTotolRecode;
    }
    public void setAlreadySetTotolRecode(boolean alreadySetTotolRecode) {
        this.alreadySetTotolRecode = alreadySetTotolRecode;
    }
    @Override
    public String toString() {
        return "Page{" +
                "pageNo=" + pageNo +
                ", pageSize=" + pageSize +
                ", totalCount=" + totalCount +
                ", totalPage=" + totalPage +
                ", startIndex=" + startIndex +
                ", endIndex=" + endIndex +
                ", results=" + results +
                ", alreadySetTotolRecode=" + alreadySetTotolRecode +
                '}';
    }
}
立即学习“Java免费学习笔记(深入)”;

 

以上就是Java实战之html分页设计的详细内容,更多请关注php中文网其它相关文章!
 
                        
                        java怎么学习?java怎么入门?java在哪学?java怎么学才快?不用担心,这里为大家提供了java速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
 
                 
                                
                                 收藏
收藏
                                                                             
                                
                                 收藏
收藏
                                                                             
                                
                                 收藏
收藏
                                                                            Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号