[Spring] 게시판에 페이지 기능 추가하기 Paging (Oracle)
복붙해서 만든 DTO로만 몇군데 수정해주면 된다 (오라클 DB일 경우 사용)
public class Paging {
private List<BoardDTO> list;
private int totalCount;
private int pageSize;
private int currentPage;
private int totalPage;
private int startNo;
private int endNo;
private int startPage;
private int endPage;
public Paging(int totalCount, int pageSize, int currentPage) {
this.totalCount = totalCount;
this.pageSize = pageSize;
this.currentPage = currentPage;
calc();
}
private void calc() {
if(this.totalCount>0){
this.totalPage = (this.totalCount-1)/this.pageSize + 1;
if(this.currentPage<1 || this.currentPage>this.totalPage)
this.currentPage = 1;
this.startNo = (this.currentPage-1) * this.pageSize + 1;
this.endNo = this.startNo + this.pageSize -1;
if(this.endNo>this.totalCount) this.endNo = this.totalCount;
this.startPage = (this.currentPage-1)/this.pageSize * this.pageSize+1;
this.endPage = this.startPage+this.pageSize - 1;
if(this.endPage>this.totalPage) this.endPage=this.totalPage;
}else{
totalCount=0;
}
}
public List<BoardDTO> getList() {
return list;
}
public void setList(List<BoardDTO> list) {
this.list = list;
}
public int getTotalCount() {
return totalCount;
}
public void setTotalCount(int totalCount) {
this.totalCount = totalCount;
calc();
}
public int getPageSize() {
return pageSize;
}
public void setPageSize(int pageSize) {
this.pageSize = pageSize;
calc();
}
public int getCurrentPage() {
return currentPage;
}
public void setCurrentPage(int currentPage) {
this.currentPage = currentPage;
calc();
}
public int getTotalPage() {
return totalPage;
}
public int getStartNo() {
return startNo;
}
public int getEndNo() {
return endNo;
}
public int getStartPage() {
return startPage;
}
public int getEndPage() {
return endPage;
}
}
'게임 개발 초보자 > 초보자의 개발일기' 카테고리의 다른 글
[디자인패턴] 싱글톤으로 클래스 만들기 (0) | 2018.06.28 |
---|---|
[Spring Security4] HelloWorld Test (0) | 2018.06.05 |
[Spring] 서버 DB에 테이블 만들기(Oracle, MariaDB) (0) | 2018.06.04 |
[Spring] Mybatis 설정 (0) | 2018.06.04 |
[Spring] Filter를 이용해 한글 안깨지게 인코딩하기 (0) | 2018.06.04 |