2018년 2월 27일 화요일

[jsp]게시판 페이징 처리

//페이징 처리 관련 유틸 ㅋ르래스

public class QuerystringPageing {

int total;
int total_page;
int curr_page;
int row = 10;
int page_row = 5;

/**
* non querystring paging
* @param total - 총 레코드갯수
* @param curr_page - 현재 페이지
*/
public QuerystringPageing(int total, int curr_page) {
this.total = total;
this.curr_page = curr_page;
this.total_page = (int) Math.ceil(total/this.row);
}

/**
* non querystring paging
* @param total - 총 레코드갯수
* @param curr_page - 현재 페이지
* @param row - 화면상 디스플레이될 레코드의 수
*/
public QuerystringPageing(int total, int curr_page, int row) {
this.total = total;
this.curr_page = curr_page;
this.row = row;
this.total_page = (int) Math.ceil(( double )total/( double )row);
}

/**
* non querystring paging
* @param total - 총 레코드갯수
* @param curr_page - 현재 페이지
* @param row - 화면상 디스플레이될 레코드의 수
* @param page_row - 화면상 디스플레이 될 페이지 네비게이션 갯수
*/
public QuerystringPageing(int total, int curr_page, int row, int page_row) {
this.total = total;
this.curr_page = curr_page;
this.row = row;
this.total_page = (int) Math.ceil(( double )total/( double )row);
this.page_row = page_row;
}

/**
* DB limit용 변수와 총 페이지수 반환
* @return HashMap<String, Object>
* @return start - mysql limit 시작row
* @return end - mysql limit offset
* @return total_page - 총 페이지 갯수
*/
public HashMap<String, Object> getLimit(){
int rs_start = row*(this.curr_page-1);
HashMap<String, Object> param = new HashMap<String, Object>();
param.put("start", rs_start);
param.put("end", this.row);
param.put("total_page", this.total_page);
return param;
}

/**
* jsp용 페이지 네비게이션 반환
* @param formId jsp상 기술된 리스트의 form id
* @return String
*/
public String getScript(String formId){
String script = "";
int page_group_no = (this.curr_page-1)/this.page_row;
int total_group_no = ((int)(Math.ceil((double)(this.total_page)/this.page_row)) - 1);
int start = page_group_no*this.page_row;
int end = start+this.page_row;
int last_page = 0;
script += "<td align='center' class='paginate'>";

if(page_group_no>0){
script += " <a href='javascript:go_page(1);' class='pre'>처음</a>";
script += " <a href='javascript:go_page("+((page_group_no-1)*this.page_row+1)+");' class='pre'>이전</a>";
}

for(int i=start;i<end;i++){
if(i==this.total_page)break;
int ii = i+1;
String cls = "";
if(ii==this.curr_page) {
script += " <strong>" + ii + "</strong>";
}else{
script += " <a href='javascript:go_page("+ii+");' "+cls+">"+ii+"</a>";
}

}

if(page_group_no<total_group_no){
script += " <a href='javascript:go_page("+((page_group_no+1)*this.page_row+1)+");' class='next'>다음</a>";
script += " <a href='javascript:go_page("+((total_group_no)*this.page_row+1)+");' class='next'>끝</a>";
}

script += "</td>";

script += "<script>";
script += "function go_page(page){";
script += " $('#page').val(page);";
script += " $('#"+formId+"').submit();";
script += "}";
script += "</script>";

return script;
}
}

//관련 스타일시트

.paginate a,.paginate strong {
position: relative;
display: inline-block;
margin-right: 1px;
padding: 3px 3px 5px 3px;
color: #000;
text-decoration: none;
border: 1px solid #ffffff;
font: bold 12px/normal Verdana;
_width /**/: 17px;
}

.paginate strong {
color: #f23219 !important;
border: 1px solid #e9e9e9;
}

.paginate .pre {
margin-right: 9px;
padding: 5px 6px 5px 6px;
_padding-bottom: 3px;
}

.paginate .next {
margin-left: 9px;
padding: 5px 6px 5px 6px;
_padding-bottom: 3px;
}

.paginate .pre,.paginate .next
{
top: -1px;
padding-bottom: 3px;
}

.paginate .pre, .paginate .next {
display: inline-block;
color: #ccc;
border: 1px solid #e9e9e9;
position: relative;
top: 1px;
_top: -1px;
font: 12px/normal arial;
_width /**/: 84px;
}

.paginate a.pre, .paginate a.next {
color: #565656;
}

.paginate a:hover {
background-color: #f7f7f7 !important;
border: 1px solid #e9e9e9;
}

서비스단 로직.
//화면에 리턴할 객체
HashMap<String,Object> resultMap = new HashMap<String,Object>();

//디비조회용 파라미터 객체
HashMap<String,Object> paramMap = new HashMap<String,Object>();

//해당 게시글의 전체 개수 가져오기 (예: 총쪽지개수)
int total = myPageDao.getLetterListCount(paramMap);

//현재 페이지 번호 (값이 없을 경우 기본 1)
String page = !StringUtils.isEmpty(req.getParameter("page")) ? req.getParameter("page") : "1";

//페이지별 노출 글 개수(값이 없을 경우 기본 10)
String pageSize = !StringUtils.isEmpty(req.getParameter("pageSize")) ?req.getParameter("pageSize") : "10";

//위에서 만든 QuerystringPageing 객체의 생성자를 호출 하여  총글개수,현재페이지
//,페이지 노출 개수를 인자값으로 전달한다.
QuerystringPageing paging = new QuerystringPageing(total, Integer.parseInt(page),Integer.parseInt(pageSize));
paramMap.put("page", (int) paging.getLimit().get("start"));
paramMap.put("pageSize", (int) paging.getLimit().get("end"));

//현재 페이지에 맞는 쪽지 리스트 셀렉트해 오기
resultMap.put("letterList",(ArrayList<HashMap<String,Object>>)myPageDao.getLetterList(paramMap));

//paging 객체에 getScript 메소드를 호출 하고 화면단에서 사용할 form 태그 id 값을
// 넘긴다.
resultMap.put("paging", paging.getScript("letterListForm"));

//현재 페이지값 ,글개수 ,토탈 정보를 화면단에 넘기기위해 resultMap 에저장
resultMap.put("page", page);
resultMap.put("pageSize", pageSize);
resultMap.put("total", total);
return resultMap;


jsp

<form id="inquiryListForm" action="/myPage/inquiryList.do">
<input type="hidden" id="page" name="page" value="${resultMap.page}">
<input type="hidden" name="pageSize" value="${resultMap.pageSize}">

jstl foreach 구문을 통해 가져온 letterList 화면에 뿌리고

.
.
.
.
.
</form>


<table>
<tbody>
                 이렇게 화면에 페이징 버튼이 위치 할곳에 넣어주면 css 정의한 디자인 대로                   적용되어서 노출 된다.
<tr>${resultMap.paging }</tr>
</tbody>
</table>




댓글 없음:

댓글 쓰기

[lunux]리눅스 폴더별 용량 확인

리눅스 폴더별 용량 확인 조회 하고자 하는 디렉토리 리스트가있는 경로로 이동후 du -h --max-depth=1