码迷,mamicode.com
首页 > 数据库 > 详细

Java Mysql分页显示

时间:2015-05-24 07:46:30      阅读:176      评论:0      收藏:0      [点我收藏+]

标签:

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; 

    }  
} 

 

Java Mysql分页显示

标签:

原文地址:http://www.cnblogs.com/xuhuaiqu/p/4525320.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!