앱)paging 관련

Posted by HULIA(휴리아)
2018. 11. 14. 21:55 백엔드개발/자바스프링
commonUtil.java
public static void setPagingParmas(ModelAndView view, int totalCount, int pageNo){
 if(totalCount != 0)
{
  int countPerPage = CommConfig.getCountPerPage();
int totalPageCount = totalCount / countPerPage;
if(totalCount%countPerPage != 0){
   totalPageCount ++;
}
int startPageNo = (pageNo / 10) *10 +1;
if(pageNo %10 ==0){
startPageNo = startPageNo - 10;
}

int endPageNo = startPageNo + 9;
if(endPageNo > totalPageCount){
 endPageNo = totalPageCount;
}

view.addObject("pageNo",String.ValueOf(pageNo));
view.addObject("totalCount",String.ValueOf(totalCount));
view.addObject("countPerPage",String.ValueOf(countPerPage));
view.addObject("totalPageCount",String.ValueOf(totalPageCount));
view.addObject("startPageNo",String.ValueOf(startPageNo));
view.addObject("endPageNo",String.ValueOf(endPageNo));

}else{
   view.addObject("totalCount",String.ValueOf(totalCount));
}

}



*Table.jsp
<@include file="/WEB-INF/jsp/common/paging.jsp" %>

<script type="text/javascript">
$(document).ready(function(){
$('#totalCount').text('${totalCount'}');
}
</script>



paging.jsp
<%@ page contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page import=util.CommConfig" %>

<script type="text/javascript">
function movePage(type, pageNo){
var moveType=parseInt(type);
var totalPageCount = parseInt("${totalPageCount}");
var intPageNo = parseInt(pageNo);
var nextPageNo = 0;

switch(moveType){
case 0://10페이지 전으로
if(intPageNo < 12){
      nextPageNo = 1;
    } else{
     nextPageNo = intPageNo - 10;
   }
break;

case 1://1페이지 저으로
        if(intPageNo == 1){
         nextPageNo = 1;
       } else{
           nextPageNo = intPageNo - 1;
       }
    break;
case 2:
nextPageNo = intPageNo;
break;
case 3://한페이지 다음으로
if(intPageNo == totalPageCount){
      nextPageNo = intPageNo;
      }else {
         nextPageNo = intPageNo +1;
      }
    break;
case 4://10페이지 다음으로
if(intPageNo == totalPageCount){
 nextPageNo = intPageNo;
} else if ((${pageNo} + 10) > totalPageCount){
       nextPageNo = totalPageCount;
    }else{
        nextPageNo = intPageNo + 10;
     }
break;

}
goPage(nextPageNo);

}
</script>


<c:if test="${totalCount != '0'}">
<p class="paging">
  <a class="next" href="#" onclick="movePage('0', '${pageNo}');">이전</a>
  <a class="next" href="#" onclick="movePage('1', '${pageNo}');">이전</a>

<c:forEach var="page" begin="${startPageNo}" end="${endPageNo}">
<c:choose>
 <c:when test="${pageNo == page}">
 <strong>${page}</strong>
 </c:when>
<c:otherwise>
<a href="#" onclick="movePage('2','${page}');">${page}</a>
</c:otherwise>
</c:choose>
</c:forEach>

  <a class="next" href="#" onclick="movePage('3', '${pageNo}');">다음</a>
  <a class="next" href="#" onclick="movePage('4', '${pageNo}');">다음</a>
</c:if>