123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- package com.caimei.entity;
- import java.io.Serializable;
- import java.util.Collection;
- import java.util.List;
- public class CmMallPage<T> implements Serializable{
- private static final long serialVersionUID = 1L;
- private int index;//当前页码
- private int pageSize;//每页大小
- private int totalRecord;//总记录数
- private int totalPage;//总页数?
- private boolean hasNextPage;//是否有后一页
- private boolean hasPreviousPage;//是否有前一页
- List<T> results;//查询结果
-
- public CmMallPage(List<T> list){
- if(list instanceof com.github.pagehelper.Page){
- com.github.pagehelper.Page<T> page = (com.github.pagehelper.Page<T>)list;
- this.index = page.getPageNum();
- this.pageSize = page.getPageSize();
- this.totalRecord = (int) page.getTotal();
- this.totalPage = page.getPages();
- setHasPreviousAndNext();
- this.results = page;
- }else if(list instanceof Collection){
- this.index = 1;
- this.pageSize = list.size();
- this.totalRecord = list.size();
- this.totalPage = 1;
- this.results = list;
- }
- }
-
- public CmMallPage(int index, int pageSize, int totalRecord, List<T> results) {
- super();
- this.index = index;
- this.pageSize = pageSize;
- this.totalRecord = totalRecord;
- this.totalPage = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
- this.results = results;
- if(this.index<2){
- hasPreviousPage=false;
- }else{
- hasPreviousPage=true;
- }
- if(this.index<totalPage){
- hasNextPage = true;
- }else{
- hasNextPage = false;
- }
- }
-
- public CmMallPage(int index, int maxSize, int totalRecord, int totalPage,
- List<T> results) {
- super();
- this.index = index;
- this.pageSize = maxSize;
- this.totalRecord = totalRecord;
- this.totalPage = totalPage;
- this.results = results;
- if(this.index<2){
- hasPreviousPage=false;
- }else{
- hasPreviousPage=true;
- }
- if(this.index<totalPage){
- hasNextPage = true;
- }else{
- hasNextPage = false;
- }
- }
- public void setHasPreviousAndNext(){
- if(this.index<2){
- hasPreviousPage=false;
- }else{
- hasPreviousPage=true;
- }
- if(this.index<totalPage){
- hasNextPage = true;
- }else{
- hasNextPage = false;
- }
- }
-
- public CmMallPage() {
- super();
- }
- public int getIndex() {
- return index;
- }
- public void setIndex(int index) {
- this.index = index;
- }
- public int getPageSize() {
- return pageSize;
- }
- public void setPageSize(int maxSize) {
- this.pageSize = maxSize;
- }
- public int getTotalRecord() {
- return totalRecord;
- }
- public void setTotalRecord(int totalRecord) {
- this.totalRecord = totalRecord;
- }
- public int getTotalPage() {
- return totalPage;
- }
- public void setTotalPage(int totalPage) {
- this.totalPage = totalPage;
- }
- public List<T> getResults() {
- return results;
- }
- public void setResults(List<T> results) {
- this.results = results;
- }
-
-
- public boolean isHasNextPage() {
- return hasNextPage;
- }
- public void setHasNextPage(boolean hasNextPage) {
- this.hasNextPage = hasNextPage;
- }
- public boolean isHasPreviousPage() {
- return hasPreviousPage;
- }
- public void setHasPreviousPage(boolean hasPreviousPage) {
- this.hasPreviousPage = hasPreviousPage;
- }
- public int countTotalPage(){
- int total = totalRecord % pageSize == 0 ? totalRecord/pageSize : totalRecord/pageSize+1;
- this.setTotalPage(total);
- return total;
- }
-
- }
|