/trunk/springmvc/src/main/java/com/def/springmvc/util/Page.java
https://gitlab.com/BGCX262/zy-myjava-svn-to-git · Java · 145 lines · 107 code · 30 blank · 8 comment · 7 complexity · 40b495db96e1f2a87067bc629fe587e2 MD5 · raw file
- package com.def.springmvc.util;
- import java.util.List;
- /**
- *
- * @author <a href="mailto:haozhonghu@hotmail.com">gavin</a>
- * @since 0.1.0
- * @create May 16, 2011 - 3:51:31 PM
- * <a href="http://www.opensourceforce.org">开源力量</a>
- */
- public class Page<T> {
- protected Integer pageNo = 1;
- protected Integer pageSize = -1;
- protected Boolean autoCount = Boolean.TRUE;
- protected List<String> orderList = CollectionUtil.newArrayList();
- protected List<String> ascOrderList = CollectionUtil.newArrayList();
- protected List<String> descOrderList = CollectionUtil.newArrayList();
- protected List<T> result = CollectionUtil.newArrayList();
- protected Long totalCount = -1L;
- public Page() {
- }
- public Page(int pageSize) {
- this.pageSize = pageSize;
- }
- public Integer getPageNo() {
- return pageNo;
- }
- public Page<T> setPageNo(Integer pageNo) {
- this.pageNo = pageNo;
- if (pageNo < 1) {
- this.pageNo = 1;
- }
- return this;
- }
- public Integer getPageSize() {
- return pageSize;
- }
- public Page<T> setPageSize(Integer pageSize) {
- this.pageSize = pageSize;
- return this;
- }
- public Integer getFirst() {
- return ((pageNo - 1) * pageSize) + 1;
- }
- public Boolean getAutoCount() {
- return autoCount;
- }
- public Page<T> setAutoCount(Boolean autoCount) {
- this.autoCount = autoCount;
- return this;
- }
- public List<T> getResult() {
- return result;
- }
- public Page<T> setResult(List<T> result) {
- this.result = result;
- return this;
- }
- public Long getTotalCount() {
- return totalCount;
- }
- public Page<T> setTotalCount(Long totalCount) {
- this.totalCount = totalCount;
- return this;
- }
- public Long getTotalPages() {
- if (totalCount < 0) {
- return -1L;
- }
- long count = totalCount / pageSize;
- if (totalCount % pageSize > 0) {
- count++;
- }
- return count;
- }
- public Boolean getHasNext() {
- return (pageNo + 1 <= getTotalPages());
- }
- public Integer getNextPage() {
- if (getHasNext()) {
- return pageNo + 1;
- } else {
- return pageNo;
- }
- }
- public Boolean getHasPre() {
- return (pageNo - 1 >= 1);
- }
- public Integer getPrePage() {
- if (getHasPre()) {
- return pageNo - 1;
- } else {
- return pageNo;
- }
- }
-
- //
- public List<String> getOrderList() {
- return orderList;
- }
-
- public List<String> getAscOrderList() {
- return ascOrderList;
- }
-
- public List<String> getDescOrderList() {
- return descOrderList;
- }
-
- public Page<T> asc(String column) {
- orderList.add(column + " ASC");
- ascOrderList.add(column);
- return this;
- }
-
- public Page<T> desc(String column) {
- orderList.add(column + " DESC");
- descOrderList.add(column);
- return this;
- }
-
- }