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

数据库分页查询

时间:2015-08-11 10:04:17      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:

1.分页查询辅助类

package com.commons;

public class Pager {
    private int totalRows; //总行数
    private int pageSize = 5; //每页显示的行数
    private int currentPage; //当前页号
    private int totalPages; //总页数
    private int startRow; //当前页在数据库中的起始行
    
    public Pager() {
    }
    public Pager(int _totalRows) {
        totalRows = _totalRows;
        totalPages=totalRows/pageSize;
        int mod=totalRows%pageSize;
        if(mod>0){
        totalPages++;
        }
        currentPage = 1;
        startRow = 0;
    }
    
    public int getTotalRows() {
        return totalRows;
    }
    public void setTotalRows(int totalRows) {
        this.totalRows = totalRows;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public int getCurrentPage() {
        return currentPage;
    }
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
    public int getTotalPages() {
        return totalPages;
    }
    public void setTotalPages(int totalPages) {
        this.totalPages = totalPages;
    }
    public int getStartRow() {
        return startRow;
    }
    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }
    public void first() {
        currentPage = 1;
        startRow = 0;
    }
    public void previous() {
        if (currentPage == 1) {
            return;
        }
        currentPage--;
        startRow = (currentPage - 1) * pageSize;
    }
    public void next() {
        if (currentPage < totalPages) {
            currentPage++;
        }
        startRow = (currentPage - 1) * pageSize;
    }
    public void last() {
        currentPage = totalPages;
        startRow = (currentPage - 1) * pageSize;
    }
    public void refresh(int _currentPage) {
        currentPage = _currentPage;
        if (currentPage > totalPages) {
            last();
        }
    }
}

 

数据库分页查询

标签:

原文地址:http://www.cnblogs.com/bobodeboke/p/4720043.html

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