본문 바로가기
자바웹프로그래밍/전자정부프레임워크-번외

전자정부 프레임워크 Paging 시스템 ? PaginatnionINfo

by 디찌s 2020. 4. 23.
728x90
반응형

1. PaginatnionInfo.class

 

public class PaginationInfo {

	/**
	 * Required Fields
	 * - 이 필드들은 페이징 계산을 위해 반드시 입력되어야 하는 필드 값들이다.  
	 * 
	 * currentPageNo : 현재 페이지 번호
	 * recordCountPerPage : 한 페이지당 게시되는 게시물 건 수
	 * pageSize : 페이지 리스트에 게시되는 페이지 건수,
	 * totalRecordCount : 전체 게시물 건 수. 
	 */

	private int currentPageNo;
	private int recordCountPerPage;
	private int pageSize;
	private int totalRecordCount;

	public int getRecordCountPerPage() {
		return recordCountPerPage;
	}

	public void setRecordCountPerPage(int recordCountPerPage) {
		this.recordCountPerPage = recordCountPerPage;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getCurrentPageNo() {
		return currentPageNo;
	}

	public void setCurrentPageNo(int currentPageNo) {
		this.currentPageNo = currentPageNo;
	}

	public void setTotalRecordCount(int totalRecordCount) {
		this.totalRecordCount = totalRecordCount;
	}

	public int getTotalRecordCount() {
		return totalRecordCount;
	}

	/**
	 * Not Required Fields
	 * - 이 필드들은 Required Fields 값을 바탕으로 계산해서 정해지는 필드 값이다.
	 * 
	 * totalPageCount: 페이지 개수
	 * firstPageNoOnPageList : 페이지 리스트의 첫 페이지 번호
	 * lastPageNoOnPageList : 페이지 리스트의 마지막 페이지 번호
	 * firstRecordIndex : 페이징 SQL의 조건절에 사용되는 시작 rownum. 
	 * lastRecordIndex : 페이징 SQL의 조건절에 사용되는 마지막 rownum.
	 */

	private int totalPageCount;
	private int firstPageNoOnPageList;
	private int lastPageNoOnPageList;
	private int firstRecordIndex;
	private int lastRecordIndex;

	public int getTotalPageCount() {
		totalPageCount = ((getTotalRecordCount() - 1) / getRecordCountPerPage()) + 1;
		return totalPageCount;
	}

	public int getFirstPageNo() {
		return 1;
	}

	public int getLastPageNo() {
		return getTotalPageCount();
	}

	public int getFirstPageNoOnPageList() {
		firstPageNoOnPageList = ((getCurrentPageNo() - 1) / getPageSize()) * getPageSize() + 1;
		return firstPageNoOnPageList;
	}

	public int getLastPageNoOnPageList() {
		lastPageNoOnPageList = getFirstPageNoOnPageList() + getPageSize() - 1;
		if (lastPageNoOnPageList > getTotalPageCount()) {
			lastPageNoOnPageList = getTotalPageCount();
		}
		return lastPageNoOnPageList;
	}

	public int getFirstRecordIndex() {
		firstRecordIndex = (getCurrentPageNo() - 1) * getRecordCountPerPage();
		return firstRecordIndex;
	}

	public int getLastRecordIndex() {
		lastRecordIndex = getCurrentPageNo() * getRecordCountPerPage();
		return lastRecordIndex;
	}
}

 

위와 같이 전자정부 프레임워크는 PaginatnionInfo 라는 클래스로 게시판 paging을 관리하고있다.

 

내용을 보면

 



	private int currentPageNo;
	private int recordCountPerPage;
	private int pageSize;
	private int totalRecordCount;
    
 
	private int totalPageCount;
	private int firstPageNoOnPageList;
	private int lastPageNoOnPageList;
	private int firstRecordIndex;
	private int lastRecordIndex;

 


 * Required Fields
 * - 이 필드들은 페이징 계산을 위해 반드시 입력되어야 하는 필드 값들이다.  
 * currentPageNo : 현재 페이지 번호
 * recordCountPerPage : 한 페이지당 게시되는 게시물 건 수
 * pageSize : 페이지 리스트에 게시되는 페이지 건수,
 * totalRecordCount : 전체 게시물 건 수. 
 * Not Required Fields
 * - 이 필드들은 Required Fields 값을 바탕으로 계산해서 정해지는 필드 값이다.
 * 
 * totalPageCount: 페이지 개수
 * firstPageNoOnPageList : 페이지 리스트의 첫 페이지 번호
 * lastPageNoOnPageList : 페이지 리스트의 마지막 페이지 번호
 * firstRecordIndex : 페이징 SQL의 조건절에 사용되는 시작 rownum. 
 * lastRecordIndex : 페이징 SQL의 조건절에 사용되는 마지막 rownum.

 

등등 필드들이 있으며

 

각각의 계산값은

 

totalPageCount =((전체 게시물 건수 - 1)/ 한 페이지당 게시되는 게시물 건수) 이다

 

예를들어 전체 게시글이 100개라면 recordCountPerPage를 5라고 설정할경우

totalPageCount = (100-1)/5  = 19.8 이며 int형태라 19 라는 페이지 번호가 나온다

 

firstPageNoOnPagelist = ((현재 페이지 번호)-1)/페이지 리스트에 게시되는 페이지 건수)*페이지 리스트에 게시되는 페이지 건수 +1

 

 

lastPageNoOnpagelist = 페이지 리스트 첫 페이지 번호 + 페이지리스트에 게시되는 페이지건수 -1;

 

firstRecordIndex = (현재 페이지번호 -1) * 한 페이지당 게시되는 게시물 건수(10)

lastRecordIndex = (현재 페이지번호)* 한 페이지당 게시되는 게시물 건수(10)

 

예를들어 현재 누른 페이지번호가 2이면 firstindex는  2-1 * 10  = 10 이고 lastindex는 2*10 =20

 

 

sql문에서  LIMIT 절을 통해서  LIMIT (recordCountPerPage )10 OFFSET (firstindex)10 으로 써서

 

10개에 내용을 가져올수있다.

 

 

728x90
반응형

댓글