본문 바로가기

SpringFramework/게시판

게시판 간단한 페이징 기능

list.jsp

${totalCount - (curPage - 1) * pageCount - status.index}

controller.java

/* //페이징 처리하기 //한 페이지에 보여질 게시글 수 int pageCount = 10; //한 페이지에 보여질 블럭 수 int blockCount = 10; //전체 글 갯수 int totalCount = service.countArticle(); //전체 페이지 수 int totalPage = totalCount / pageCount; if(totalCount % pageCount > 0) totalPage++; //페이지의 시작번호 int startPage = (curPage - 1) * pageCount + 1; //페이지의 끝번호 int endPage = startPage + pageCount - 1; //블럭의 시작번호 int blockStart = ((curPage - 1) / blockCount) * blockCount + 1; //블럭의 끝 번호 int blockEnd = blockStart + blockCount - 1; if(blockEnd > totalPage) blockEnd = totalPage; */ //전체 글 갯수 int totalCount = service.countArticle(); PageDTO pageDTO = new PageDTO(totalCount, curPage);


PageDTO

package com.munhwasudo.web.dto; public class PageDTO { public static final int PAGE_COUNT = 10; // 페이지당 게시물 수 public static final int BLOCK_COUNT = 10; // 한 페이지에 보여질 블럭 수 private int curPage; // 현재페이지 private int totalCount; // 전체 게시글 수 private int totalPage; // 전체 페이지 수 private int startPage; // 페이지의 시작번호 private int endPage; // 페이지의 끝번호 private int blockStart; // 블럭의 시작번호 private int blockEnd; // 블럭의 끝 번호 public PageDTO(int totalCount, int curPage){ this.curPage = curPage; setTotalPage(totalCount); setStartPage(curPage); setEndPage(startPage); setBlockStart(curPage); setBlockEnd(blockStart); } public int getPage_counter(){ return PAGE_COUNT; } // 전체 페이지 계산 public void setTotalPage(int totalCount) { totalPage = totalCount / PAGE_COUNT; if (totalCount % PAGE_COUNT > 0) { totalPage++; } } public int getCurPage() { return curPage; } public void setCurPage(int curPage) { this.curPage = curPage; if(curPage < 0) curPage = 1; } public int getTotalCount() { return totalCount; } public void setTotalCount(int totalCount) { this.totalCount = totalCount; } public int getStartPage() { return startPage; } public void setStartPage(int curPage) { // this.startPage = startPage; startPage = (curPage - 1) * PAGE_COUNT + 1; } public int getEndPage() { return endPage; } public void setEndPage(int startPage) { // this.endPage = endPage; this.endPage = startPage + PAGE_COUNT - 1; } public int getBlockStart() { return blockStart; } public void setBlockStart(int curPage) { // this.blockStart = blockStart; blockStart = ((curPage - 1) / BLOCK_COUNT) * BLOCK_COUNT + 1; } public int getBlockEnd() { return blockEnd; } public void setBlockEnd(int blockStart) { // this.blockEnd = blockEnd; blockEnd = blockStart + BLOCK_COUNT - 1; if (blockEnd > totalPage) blockEnd = totalPage; } public int getTotalPage() { return totalPage; } }


'SpringFramework > 게시판' 카테고리의 다른 글

첨부파일 다운로드.  (0) 2020.02.26