java簡單分頁工具類,java工具類

來源:互聯網
上載者:User

java簡單分頁工具類,java工具類

 1 import java.util.List; 2  3 /** 4  *  分頁工具 5  * @author Administrator 6  * 7  */ 8 public class PageBean<T> { 9 10     private int pageNo = 1;  //當前頁11     private int pageSize = 4; //每頁個數12     private int totalCount;  //總記錄數13     private int totalPages;  //總頁數--唯讀14     private List<T> pageList;  //每頁對應的集合泛型15     public int getPageNo() {16         return pageNo;17     }18     //當前頁碼不能小於1不能大於總頁數19     public void setPageNo(int pageNo) {20         if(pageNo<1)21             this.pageNo = 1;22         else if(pageNo > totalPages)23             this.pageNo = totalPages;24         else25             this.pageNo = pageNo;26     }27     public int getPageSize() {28         return pageSize;29     }30     public void setPageSize(int pageSize) {31         this.pageSize = pageSize;32     }33     //總記錄數決定總頁數34     public void setTotalCount(int totalCount) {35         this.totalCount = totalCount;36         this.totalPages = (this.totalCount%this.pageSize==0)?this.totalCount/this.pageSize:this.totalCount/this.pageSize+1;37     }38     public int getTotalCount() {39         return totalCount;40     }41     42     //唯讀43     public int getTotalPages() {44         return totalPages;45     }46     47     48     public List<T> getPageList() {49         return pageList;50     }51     public void setPageList(List<T> pageList) {52         this.pageList = pageList;53     }54     public PageBean(int pageNo, int pageSize, int totalCount, int totalPages,55             List<T> pageList) {56         super();57         this.pageNo = pageNo;58         this.pageSize = pageSize;59         this.totalCount = totalCount;60         this.totalPages = totalPages;61         this.pageList = pageList;62     }63     public PageBean() {64         super();65         // TODO Auto-generated constructor stub66     }6768 }

mysql分頁:select * from 表 limit (pageNo-1)*pageSize,pageSize; 

oracle分頁:select a.* (select 表.*,rowum rn from 表) a where rn>(pageNo-1)*pageSize and rn <=pageNo*pageSize;

這是一個最簡單分頁工具類,順便附上mysql以及oracle分頁語句,大佬勿噴,僅供參考。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.