分頁查詢SQL&&Page對象

Mysql 分頁查詢: select * from 表明 where 1=1 limit 0,10
limit 0,10
0 代表數據庫裏 記錄 起始行的下標 =(當前頁頁碼-1)*每頁顯示的數據量
10代表每頁 多少條
SQL Server 語法 :select top 3 * from NEWS where ID not in
(select top 0 ID from NEWS)
內層 select top 0 ID from NEWS 0 代表數據庫裏 記錄 起始行的下標 =(當前頁頁碼-1)*每頁顯示的數據量
外層 select top 3 代表每次 返回多少條

//page 類用來做分頁
public class Page {
    //current page 當前頁碼
    private int currPage;
    //pagesize 每頁數量
    private int pageSize; 
    //total count 總條數
    private int totalCount;
    //totalpage 總頁數
    private int totalPageCount;
    public int getCurrPage() {
        return currPage;
    }
    public void setCurrPage(int currPage) {
        this.currPage = currPage;
    }
    public int getPageSize() {
        return pageSize;
    }
    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }
    public int getTotalCount() {
        return totalCount;
    }
    public void setTotalCount(int totalCount) {
    //設置記錄總條數時,順便計算一下總頁數
        this.totalCount = totalCount;
        if(totalCount%pageSize==0){
            this.totalPageCount = totalCount/pageSize;
        }else{
            this.totalPageCount = totalCount/pageSize+1;
        }

    }
    public int getTotalPageCount() {
        return totalPageCount;
    }

    public Page(int currPage, int pageSize, int totalCount, int totalPageCount) {
        super();
        this.currPage = currPage;
        this.pageSize = pageSize;
        this.totalCount = totalCount;
        this.totalPageCount = totalPageCount;
    }
    public Page() {
        super();
        // TODO Auto-generated constructor stub
    }
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章