Skip to content

Instantly share code, notes, and snippets.

@YongWanJin
Created August 7, 2023 11:58
Show Gist options
  • Save YongWanJin/a888233d1e9ab7ba2879f94d70fdd963 to your computer and use it in GitHub Desktop.
Save YongWanJin/a888233d1e9ab7ba2879f94d70fdd963 to your computer and use it in GitHub Desktop.
2023.08.07. Mission1 "깜짝과제" 3번
import java.util.*;
class Pager{
long totalCount; // 전체 게시글 수
long NumPerPage = 10; // 한 페이지당 보여지는 게시글 수
long blockLength = 10; // 페이지 네비게이션에서 보여주는 블럭 수
Pager(long totalCount){
this.totalCount = totalCount;
}
public String html(long pageIndex){
long blockNum = this.totalCount / this.NumPerPage + 1;
long firstBlock = this.blockLength * (pageIndex/blockLength) + 1;
long lastBlock = firstBlock + blockLength - 1;
if(lastBlock > blockNum){
lastBlock = blockNum;
}
StringBuilder sb = new StringBuilder();
sb.append("<a href='#'>[처음]</a>\n");
sb.append("<a href='#'>[이전]</a>\n\n");
for(long i = firstBlock; i <= lastBlock; i++){
if(i == pageIndex){
sb.append("<a href='#' class='on'>").append(i).append("</a>\n");
} else {
sb.append("<a href='#'>").append(i).append("</a>\n");
}
}
sb.append("\n<a href='#'>[다음]</a>\n");
sb.append("<a href='#'>[마지막]</a>");
return sb.toString();
}
}
public class Mission1Surprise3 {
public static void main(String[] args) {
long totalCount = 127; // 전체 게시글 수
long pageIndex = 11; // 현재 페이지번호
Pager pager = new Pager(totalCount);
System.out.println(pager.html(pageIndex));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment