Java simple paging tool and java Tool

Source: Internet
Author: User

Java simple paging tool and java Tool

1 import java. util. list; 2 3/** 4 * Paging tool 5 * @ author Administrator 6*7 */8 public class PageBean <T> {9 10 private int pageNo = 1; // The current page 11 private int pageSize = 4; // The number of each page 12 private int totalCount; // The total number of records 13 private int totalPages; // total number of pages -- read-only 14 private List <T> pageList; // The set of each page corresponds to a generic 15 public int getPageNo () {16 return pageNo; 17} 18 // the current page number cannot be less than 1 and cannot be greater than the total page number 19 public void setPageNo (int pageNo) {20 if (page No <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 // The total number of records determines the total number of pages 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 // read-only 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 paging: select * from Table limit (pageNo-1) * pageSize, pageSize;

Oracle paging: select a. * (select table. *, rowum rn from Table) a where rn> (pageNo-1) * pageSize and rn <= pageNo * pageSize;

This is the simplest paging tool class. By the way, mysql and oracle paging statements are attached.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.