Java Mysql分页显示

public class View { 
    private int currentPage; 
    private int pageSize; 
    private int recordCount;

    public View(int pageSize, int recordCount, int currentPage) { 

        this.pageSize = pageSize; 

        this.recordCount = recordCount; 

        this.setCurrentPage(currentPage); 

    } 
    public int getPageCount() { 

        int size = recordCount / pageSize; 

        int flag = recordCount % pageSize; 

        if (flag != 0) { 

            size++; 

        } 
        if (recordCount == 0) {
            return 1; 

        } 
        return size; 

    } 

    public int getFromIndex() { 

        return (currentPage - 1) * pageSize;

    } 

    public void setCurrentPage(int currentPage) { 

        int vaildPage = currentPage <= 0 ? 1 : currentPage; 

        vaildPage = vaildPage > this.getPageCount() ? this.getPageCount() 

                : vaildPage; 

        this.currentPage = vaildPage; 

    } 

    public int getCurrentPage() { 

        return currentPage; 

    } 

    public int getPageSize() { 

        return pageSize; 

    }  
} 

 

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。