ページング処理方法

5147 ワード

Paging1


従来の表面処理方法
	private int page; //현재 페이지 번호 
	private int start, end; //시작, 끝 페이지
	private boolean prev, next;  //이전, 다음
	private int total; //전체 데이터의 수
	
	public Paging(int page, int total) {
		this.page = page;
		this.total = total;
		
		//주소창에 음수 값을 입력했을 때 제대로 나오도록 하는 식
		page = page<= 0 ? 1:page; 
		page = page > total ? (int)(Math.ceil(total/10.0)):page;
	
		System.out.println("page: "+page);
		
		//그 장의 마지막 페이지
		int tempEnd = (int)(Math.ceil(page/10.0) * 10);
		this.start = tempEnd - 9;
		this.prev = this.start != 1;
		
		//전체 마지막 페이지
		if(tempEnd * 10 >= total) {
			this.end = (int)(Math.ceil(total/10.0));
			this.next = false;
		}else {
			this.end = tempEnd;
			this.next = true;
		}

	};

paging2


より古典的なページング処理方法(HTMLボタン自体の作成)
public class Paging {
	public int currentPage; //현재페이지 
	public int pageBlock;  //[이전][1][2][3][다음]한 페이지당 띄울 페이지 번호. 
	public int pageSize; //1페이지 당 개수
    public int total; //전체 데이터의 수
	public StringBuffer pagingHTML;
	
▶ StringBuffer / String :둘다 문자열 클래스
 - StringBuffer:편집이 가능하다. 내가 있는 현재페이지가 어디인지에 따라 내용을 바꿀 수 있다. 
	
	public void makePagingHTML() {
		pagingHTML = new StringBuffer();
		int totalP = (total+(pageSize-1))/pageSize;
		System.out.println("totalP:"+totalP);
		
		int startPage = (currentPage-1) / pageBlock * pageBlock + 1;
		
		int endPage = startPage + pageBlock - 1;
		if(endPage > totalP) {
			endPage = totalP;
		}
//		▶ [이전]/[다음]을 페이지에 추가하기.
//		1) 일반
		if(startPage > pageBlock) {
			pagingHTML.append("[<span id='paging' onclick='boardPaging("+(startPage-1)+")'>이전</span>]"); // 링크 걸어주기
		}
//		js의 boardPaging(n)을 찾아간다.
		for (int i=startPage; i<=endPage; i++) {
			if(i == currentPage) //현재페이지라면
				pagingHTML.append("[<span id='currentPaging' onclick='boardPaging("+i+")'>"+i+"</span>]");
			else
				pagingHTML.append("[<span id='paging' onclick='boardPaging("+i+")'>"+i+"</span>]");
			
		}//for
        ---> 1번 방식에서는 jsp에서 처리함
		
//		2) 마지막 페이지에는 [다음]이 없다.
		if(endPage < totalP) {
			pagingHTML.append("[ <span id ='paging' onclick='boardPaging("+(endPage+1)+")'>다음</a> ]");
		}
//		3) 1페이지는 [이전] 페이지가 없다.	
	}

	public void setCurrentPage(int parseInt) {
	}

}