[전자정부프레임워크] 페이지 네비게이션 모듈화
####소스설명은 나중에.... 집에서 하겠음####
public class PageNaviService {
// Url
private String Url;
// 현재 페이지
private int curPage;
// 한 페이지 게시글 개수
private int rowSize;
// 각 페이지당 게시글 시작 번호
private int startBoardNum;
// 각 페이지당ㅇ 게시글 마지막 번호
private int endBoardNum;
// 모든 페이지 개수
private int allPage;
// 한 블럭 시작 페이지
private int blockStartPage;
// 한 블럭 마지막 페이지
private int blockEndPage;
// 블럭
private int block;
// 모든 게시물의 총 개수
private int total;
// setter
public void setUrl(String url) {
Url = url;
}
public void setCurPage(int curPage) {
this.curPage = curPage;
}
public void setRowSize(int rowSize) {
this.rowSize = rowSize;
}
public void setStartBoardNum(int startBoardNum) {
this.startBoardNum = startBoardNum;
}
public void setEndBoardNum(int endBoardNum) {
this.endBoardNum = endBoardNum;
}
public void setAllPage(int allPage) {
this.allPage = allPage;
}
public void setBlockStartPage(int blockStartPage) {
this.blockStartPage = blockStartPage;
}
public void setBlockEndPage(int blockEndPage) {
this.blockEndPage = blockEndPage;
}
public void setBlock(int block) {
this.block = block;
}
public void setTotal(int total) {
this.total = total;
}
// Getter
public String getUrl() {
return Url;
}
public int getCurPage() {
return curPage;
}
public int getRowSize() {
return rowSize;
}
public int getStartBoardNum() {
startBoardNum = (curPage * rowSize) - (rowSize - 1);
return startBoardNum;
}
public int getEndBoardNum() {
endBoardNum = curPage * rowSize;
return endBoardNum;
}
public int getAllPage() {
allPage = (int) (Math.ceil(total / (double) rowSize));
return allPage;
}
public int getBlockStartPage() {
blockStartPage = ((curPage - 1) / block * block + 1);
return blockStartPage;
}
public int getBlockEndPage() {
blockEndPage = ((curPage - 1) / block * block) + block;
return blockEndPage;
}
public int getBlock() {
return block;
}
public int getTotal() {
return total;
}
public void SetPageVO(int curPage, int total, int block, int rowSize,
String url) {
setCurPage(curPage);
setRowSize(rowSize);
setTotal(total);
setBlock(block);
setUrl(url);
}
public String GetPageNavi(int curPage, String boardType) {
String strPageNaviHtml = "";
// int allPage = getAllPage();
// System.out.println("allPage : "+allPage);
// if (getBlockEndPage() > allPage) {
// setBlockEndPage(1);
// System.out.println("if문실행");
// }
//
if (getCurPage() > getBlock()) {
strPageNaviHtml += "[<a href='" + getUrl() + "?page=1&boardType="
+ boardType + "'>◀◀</a>]";
strPageNaviHtml += "[<a href='" + getUrl() + "?page="
+ (getBlockStartPage() - 1) + "&boardType=" + boardType
+ "'>◀</a>]";
} else if (getCurPage() <= getBlock()) {
strPageNaviHtml += "[<span style='color:gray'>◀◀</span>]";
strPageNaviHtml += "[<span style='color:gray'>◀</span>]";
}
/*
* 문제점 발생 if(getBlockEndPage() >
* getAllPage())setBlockEndPage(getAllPage()); 위의 소스가 정상적으로 작동하지 않기 때문에
* if~else if문으로 처리했다. setBlockEndPage()가 정상적으로 먹히지 않음. 원래는 아래의 소스와 동일
*/
// if (getBlockEndPage() > getAllPage())
// setBlockEndPage(getAllPage());
// for (int i = getBlockStartPage(); i <= getBlockEndPage(); i++) {
// if (i == getCurPage()) {
// strPageNaviHtml += "[" + i + "]";
// } else if (i != getCurPage()) {
// strPageNaviHtml += "[<a href='" + getUrl() + "?page=" + i
// + "&boardType=" + boardType + "'>" + i + "</a>]";
// }
// }
if (getBlockEndPage() < getAllPage()) {
for (int i = getBlockStartPage(); i <= getBlockEndPage(); i++) {
if (i == getCurPage()) {
strPageNaviHtml += "[" + i + "]";
} else if (i != getCurPage()) {
strPageNaviHtml += "[<a href='" + getUrl() + "?page=" + i
+ "&boardType=" + boardType + "'>" + i + "</a>]";
}
}
} else if (getBlockEndPage() > getAllPage()) {
for (int i = getBlockStartPage(); i <= getAllPage(); i++) {
if (i == getCurPage()) {
strPageNaviHtml += "[" + i + "]";
} else if (i != getCurPage()) {
strPageNaviHtml += "[<a href='" + getUrl() + "?page=" + i
+ "&boardType=" + boardType + "'>" + i + "</a>]";
}
}
}
if (getBlockEndPage() < getAllPage()) {
strPageNaviHtml += "[<a href='" + getUrl() + "?page="
+ (getBlockEndPage() + 1) + "&boardType=" + boardType
+ "'>▶</a>]";
strPageNaviHtml += "[<a href='" + getUrl() + "?page="
+ getAllPage() + "&boardType=" + boardType + "'>▶▶</a>]";
} else if (getBlockEndPage() >= getAllPage()) {
strPageNaviHtml += "[<span style='color:gray'>▶</span>";
strPageNaviHtml += "[<span style='color:gray'>▶▶</span>]";
}
return strPageNaviHtml;
}
}