Bläddra i källkod

페이징 클래스 추가

jsshin 5 år sedan
förälder
incheckning
4c13b17635
1 ändrade filer med 81 tillägg och 0 borttagningar
  1. 81 0
      src/main/java/com/style24/persistence/TscPageRequest.java

+ 81 - 0
src/main/java/com/style24/persistence/TscPageRequest.java

@@ -0,0 +1,81 @@
+package com.style24.persistence;
+
+import lombok.Data;
+
+import java.io.Serializable;
+
+/**
+ * Paging
+ *
+ * @author gagamel
+ * @since 2020. 01. 14
+ */
+@SuppressWarnings("serial")
+@Data
+public class TscPageRequest implements Serializable {
+
+	private final int pageNo;   // 페이지번호
+	private final int pageSize; // 조회할 row수
+	private final int pageUnit; // 그룹핑 페이지 단위
+	private int totalCount = 0; // 전체 row 건수
+
+	public TscPageRequest(int pageNo, int pageSize) {
+		this(pageNo, pageSize, 10);
+	}
+
+	public TscPageRequest(int pageNo, int pageSize, int pageUnit) {
+		if (pageNo < 0) {
+			throw new IllegalArgumentException("Current page index must not be less than zero!");
+		}
+
+		if (pageSize < 1) {
+			throw new IllegalArgumentException("Page size must not be less than one!");
+		}
+
+		if (pageUnit < 1) {
+			throw new IllegalArgumentException("Page unit must not be less than one!");
+		}
+
+		this.pageNo = pageNo;
+		this.pageSize = pageSize;
+		this.pageUnit = pageUnit;
+	}
+
+	public int getPageNo() {
+		return pageNo + 1;
+	}
+
+	public int getOffset() {
+		return pageNo * pageSize;
+	}
+
+	public int getStartRow() {
+		return pageNo * pageSize + 1;
+	}
+
+	public int getEndRow() {
+		return getOffset() + pageSize;
+	}
+
+	public int getPageGroup() {
+		return pageNo / pageUnit + 1;
+	}
+
+	public void setTotalCount(int totalCount) {
+		this.totalCount = totalCount;
+	}
+
+	public int getTotalPage() {
+		int totalPage = totalCount / pageSize;
+		if (totalCount % pageSize > 0) {
+			totalPage++;
+		}
+		return totalPage;
+	}
+
+	@Override
+	public String toString() {
+		return String.format("Page request [pageNo: %d, pageSize %d, pageUnit %d]", getPageNo(), pageSize, pageUnit);
+	}
+
+}