Java tutorial
/** * Copyright (c) 2011-2014, hubin (jobob@qq.com). * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.tj.mybatisplus.plugins.pagination; import java.io.Serializable; import org.apache.ibatis.session.RowBounds; /** * <p> * ? * </p> * ? org.apache.ibatis.session.RowBounds<br> * ???RowBounds??? * * @author hubin * @Date 2016-01-23 */ public class Pagination extends RowBounds implements Serializable { private static final long serialVersionUID = 1L; /* */ private int total; /* ?? */ private int size; /* */ private int pages; /* ? */ private int current = 1; /* true */ private boolean searchCount = true; public Pagination() { super(); } /** * <p> * * </p> * * @param current * ? * @param size * ?? */ public Pagination(int current, int size) { this(current, size, true); } public Pagination(int current, int size, boolean searchCount) { super(offsetCurrent(current, size), size); if (current > 1) { this.current = current; } this.size = size; this.searchCount = searchCount; } protected static int offsetCurrent(int current, int size) { if (current > 0) { return (current - 1) * size; } return 0; } public int getOffsetCurrent() { return offsetCurrent(this.current, this.size); } public boolean hasPrevious() { return this.current > 1; } public boolean hasNext() { return this.current < this.pages; } public int getTotal() { return total; } public void setTotal(int total) { this.total = total; this.pages = this.total / this.size; if (this.total % this.size != 0) { this.pages++; } if (this.current > this.pages) { /** * ?? */ this.current = 1; } } public int getSize() { return size; } public int getPages() { return pages; } public int getCurrent() { return current; } public boolean isSearchCount() { return searchCount; } public void setSearchCount(boolean searchCount) { this.searchCount = searchCount; } @Override public String toString() { return "Pagination { total=" + total + " ,size=" + size + " ,pages=" + pages + " ,current=" + current + " }"; } }