목차

전자정부표준프레임워크 페이징 처리

  • description : 전자정부표준프레임워크 페이징 처리
  • author : 오션
  • email : shlim@repia.com
  • lastupdate : 2022-09-01


전자정부표준프레임워크 페이징 처리

PaginationInfo.class

public class PaginationInfo {
 
	/**
	 * Required Fields
	 * - 이 필드들은 페이징 계산을 위해 반드시 입력되어야 하는 필드 값들이다.  
	 * 
	 * currentPageNo : 현재 페이지 번호
	 * recordCountPerPage : 한 페이지당 게시되는 게시물 건 수
	 * pageSize : 페이지 리스트에 게시되는 페이지 건수,
	 * totalRecordCount : 전체 게시물 건 수. 
	 */
 
	private int currentPageNo;
	private int recordCountPerPage;
	private int pageSize;
	private int 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;


SearchVO.java

public class SearchVO implements Serializable {
...
	/** 검색조건 */
	private String searchCondition = "";
 
	/** 검색Keyword */
	private String searchKeyword = "";
 
	/** 검색사용여부 */
	private String searchUseYn = "";
 
	/** 검색조건 */
	private String searchCnd = "";
 
	/** 현재페이지 */
	private int pageIndex = 1;
 
	/** 페이지갯수 */
	/* 한 페이지에 표시되는 게시물 건수(가로 행 rows의 개수) */
	private int pageUnit = 10;
 
	/** 페이지사이즈 */
	/* 페이징에 표시되는 번호들의 개수를 지정 */
	private int pageSize = 10;
 
	/** firstIndex */
	private int firstIndex = 1;
 
	/** lastIndex */
	private int lastIndex = 1;
 
	/** recordCountPerPage */
	/* 하나의 페이지 당 게시되는 게시물 수(가로 행 rows의 개수) */ 
	private int recordCountPerPage = 10;


Example

테이블에 등록된 가로 행 rows(데이터)의 총 개수가 21개인 경우,

    PaginationInfo paginationInfo = new PaginationInfo();
 
    /* 현재 페이지 번호를 저장*/
    paginationInfo.setCurrentPageNo(projMngVO.getPageIndex());
 
    /* 1개의 페이지에 표시되는 등록된 Repia 진행 프로젝트의  개수 */
    paginationInfo.setRecordCountPerPage(5);	// projMngVO.getPageUnit()
 
    /* 페이징에 표시되는 번호들의 개수를 3개로 지정 */
    /* 1,2,3이 보이고, Next버튼 클릭하면 4,5 만 보임 - 등록된 진행프로젝트 개수가 21개인 경우 */
    paginationInfo.setPageSize(3);


테이블에 등록된 가로 행 rows(데이터)의 총 개수 : 21개
하나의 페이지 당 표시되는 가로 행 rows(데이터)의 개수 : 5개
페이징에 표시되는 번호들의 개수 : 3개

firstRecordIndex = (현재 페이지 번호 - 1) * 하나의 페이지 당 표시되는 가로 행 rows의 개수
–> 현재 페이지가 4페이지인 경우 : firstRecordIndex = (4-1) * 5 = 15

lastRecordIndex = 현재 페이지 번호 * 하나의 페이지 당 표시되는 가로 행 rows의 개수
–> lastRecordIndex = 4 * 5 = 20

sql.xml

...
FROM
    TABLE_NAME
LIMIT #{recordCountPerPage} OFFSET #{firstIndex}
</select>


sql의 LIMIT clause의
LIMIT #{recordCountPerPage}에는 recordCountPerPage = 5가 입력됨
OFFSET #{firstIndex}에는 firstRecordIndex = 15가 입력됨

현재 위치한 4페이지에, OFFSET clause에 따라서 16번째의 데이터부터 5개(16~20)를 순서대로 삽입\\

결과 화면

페이징01 페이징02

페이징처리