123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- package com.tzld.piaoquan.featurestools.util.page;
- import java.util.List;
- public class Page<T> {
- public static final String DEFAULT_PAGE_SIZE = "20";
- public static final String DEFAULT_CURRENT_PAGE = "1";
- private int currentPage = Integer.valueOf(DEFAULT_CURRENT_PAGE);
- private int totalSize;
- private int pageSize = Integer.valueOf(DEFAULT_PAGE_SIZE);
- private List<T> objs;
- private T obj;
- public Page() {
- }
- public Page(int currentPage) {
- this.currentPage = currentPage;
- }
- public Page(int currentPage, int pageSize) {
- setCurrentPage(currentPage);
- setPageSize(pageSize);
- }
- public int getNextPage() {
- return currentPage == getTotalPage() ? currentPage : currentPage + 1;
- }
- public int getPrePage() {
- return currentPage > 1 ? currentPage - 1 : 1;
- }
- public int getOffset() {
- return getCurPageFirstRecNum() - 1;
- }
- public int getCurPageFirstRecNum() {
- return (getCurrentPage() - 1) * pageSize + 1;
- }
- public int getCurPageLastRecNum() {
- return getCurrentPage() * pageSize;
- }
- public int getTotalPage() {
- int t = totalSize % pageSize > 0 ? totalSize / pageSize + 1 : totalSize / pageSize;
- if (t <= 0) {
- t = 1;
- }
- return t;
- }
- public void setObjs(List<T> objs) {
- this.objs = objs;
- }
- public List<T> getObjs() {
- return objs;
- }
- public int getCurrentPage() {
- return currentPage;
- }
- public void setCurrentPage(int currentPage) {
- this.currentPage = currentPage;
- }
- public int getTotalSize() {
- return totalSize;
- }
- public void setTotalSize(int totalSize) {
- this.totalSize = totalSize;
- }
- public int getPageSize() {
- return pageSize;
- }
- public void setPageSize(int pageSize) {
- if (pageSize > 0) {
- this.pageSize = pageSize;
- }
- }
- public boolean containData() {
- return getTotalSize() > 0;
- }
- @Override
- public String toString() {
- return "Page [currentPage=" + getCurrentPage() + ", totalSize=" + getTotalSize() + ", pageSize=" + getPageSize()
- + "]";
- }
- public T getObj() {
- return obj;
- }
- public void setObj(T obj) {
- this.obj = obj;
- }
- }
|