|
@@ -0,0 +1,139 @@
|
|
|
|
+package com.caimei.entity;
|
|
|
|
+
|
|
|
|
+import java.io.Serializable;
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.List;
|
|
|
|
+
|
|
|
|
+public class Page<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 Page(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 Page(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 Page(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 Page() {
|
|
|
|
+ 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;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+}
|