gnusraun

Egov Pagination 페이지 처리 본문

Backend/Egov

Egov Pagination 페이지 처리

gnusraun 2023. 5. 13. 15:57
728x90

Egov + Java + Mybatis + Oracle

 

 

:: Egov 페이지 처리 내용

 

이름 내용 입력
여부
공식
currentPageNo 현재 페이지 번호 O  
recordCountPerPage 한 페이지당 게시되는 게시물 건 수 O  
pageSize 페이지 리스트에 게시되는 페이지 건수 O  
totalRecordCount 전체 게시물 건 수 O  
totalPageCount 페이지 개수 X totalPageCount =
((totalRecordCount-1)/recordCountPerPage) + 1
firstPageNoOnPageList 페이지 리스트의 첫 페이지 번호 X firstPageNoOnPageList =
((currentPageNo-1)/pageSize)*pageSize + 1
lastPageNoOnPageList 페이지 리스트의 마지막 페이지 번호 X lastPageNoOnPageList =
firstPageNoOnPageList+pageSize-1

if(lastPageNoOnPageList>totalRecordCount) {
lastPageNoOnPageList=totalPageCount
}
firstRecordIndex 페이징 SQL의 조건절에 사용되는 시작 rownum X firstRecordIndex =
(currentPageNo - 1) * recordCountPerPage
lastRecordIndex 페이징 SQL의 조건절에 사용되는 마지막 rownum X lastRecordIndex =
currentPageNo * recordCountPerPage

 

 

:: EgovImgPaginationRenderer.java

 

package egovframework.example.cmmn.web;

import egovframework.rte.ptl.mvc.tags.ui.pagination.AbstractPaginationRenderer;

import javax.servlet.ServletContext;

import org.springframework.web.context.ServletContextAware;

public class EgovImgPaginationRenderer extends AbstractPaginationRenderer implements ServletContextAware{

	private ServletContext servletContext;

	public EgovImgPaginationRenderer() {
		// no-op
	}

	/**
	* PaginationRenderer
	*
	* @see 개발프레임웍크 실행환경 개발팀
	*/
	public void initVariables() {

		firstPageLabel = "<a href=\"#\" onclick=\"{0}({1}); return false;\">" + "<image src='" + servletContext.getContextPath() + "/images/egovframework/cmmn/btn_page_pre10.gif' border=0/></a>&#160;";
		previousPageLabel = "<a href=\"#\" onclick=\"{0}({1}); return false;\">" + "<image src='" + servletContext.getContextPath() + "/images/egovframework/cmmn/btn_page_pre1.gif' border=0/></a>&#160;";
		currentPageLabel = "<strong>{0}</strong>&#160;";
		otherPageLabel = "<a href=\"#\" onclick=\"{0}({1}); return false;\">{2}</a>&#160;";
		nextPageLabel = "<a href=\"#\" onclick=\"{0}({1}); return false;\">" + "<image src='" + servletContext.getContextPath() + "/images/egovframework/cmmn/btn_page_next1.gif' border=0/></a>&#160;";
		lastPageLabel = "<a href=\"#\" onclick=\"{0}({1}); return false;\">" + "<image src='" + servletContext.getContextPath() + "/images/egovframework/cmmn/btn_page_next10.gif' border=0/></a>&#160;";
	}

	@Override
	public void setServletContext(ServletContext servletContext) {
		this.servletContext = servletContext;
		initVariables();
	}
}

 

 

:: dispatcher-servlet.xml

 

<!-- For Pagination Tag image -->
<bean id="imageRenderer" class="egovframework.example.cmmn.web.EgovImgPaginationRenderer"/>

<!-- For Pagination Tag text -->
<bean id="textRenderer" class="egovframework.rte.ptl.mvc.tags.ui.pagination.DefaultPaginationRenderer"/>

<bean id="paginationManager" class="egovframework.rte.ptl.mvc.tags.ui.pagination.DefaultPaginationManager">
	<property name="rendererType">
	    <map>
	        <entry key="image" value-ref="imageRenderer"/>
	        <entry key="text" value-ref="textRenderer"/>
	    </map>
	</property>
</bean>
<!-- /For Pagination Tag -->

 

 

:: WebLogController.java

 

@Controller
public class WebLogController {

	@Resource(name = "WebLogService")
	private WebLogService webLogService;
		
	// 웹 로그 리스트
	@RequestMapping(value = "/weblog.do")
	public String weblog(@RequestParam Map<String, Object> commandMap, HttpServletRequest req, ModelMap model) throws Exception {
		
		// 날짜 체크
		if(Utils.isEmpty(commandMap.get("nowDate"))) {
			Date nowTime = new Date();
			SimpleDateFormat sf = new SimpleDateFormat("yyyyMMdd");
			commandMap.put("nowDate", sf.format(nowTime));
		}
		
		// PaginationInfo에 필수 정보를 넣어 준다.
		PaginationInfo paginationInfo = new PaginationInfo();
		// 현재 페이지 체크
		if(Utils.isEmpty(commandMap.get("currentPageNo"))) {
			paginationInfo.setCurrentPageNo(1); // deault 번호	
		} else {
			paginationInfo.setCurrentPageNo(Integer.parseInt(String.valueOf(commandMap.get("currentPageNo")))) ; //현재 페이지 번호			
		}	
		
		paginationInfo.setRecordCountPerPage(10);	// 한 페이지에 게시되는 게시물 건수
		paginationInfo.setPageSize(5); 				// 페이징 리스트의 사이즈
 
		int firstRecordIndex = paginationInfo.getFirstRecordIndex();
		int recordCountPerPage = paginationInfo.getCurrentPageNo() * paginationInfo.getRecordCountPerPage();
		commandMap.put("firstIndex", firstRecordIndex);
		commandMap.put("recordCountPerPage", recordCountPerPage);
 	
		List<?> webLogList = webLogService.selectWebLogList(commandMap);	
		int webLogCount = webLogService.selectWebLogCount(commandMap);
		paginationInfo.setTotalRecordCount(webLogCount); //전체 게시물 건 수
		
		//페이징 관련 정보가 있는 PaginationInfo 객체를 모델에 반드시 넣어준다.
		model.addAttribute("paginationInfo", paginationInfo);		
		model.addAttribute("commandMap", commandMap);
		model.addAttribute("webLogList", webLogList);
		
		return "weblog/weblog";
		
	}
    
}

 

 

:: Mybatis

 

<!-- 웹로그 개수 -->
<select id="selectWebLogCount" resultType="Integer">
<![CDATA[
    SELECT
        count(*)
    FROM
       th_web_log
    WHERE
        substr(reg_dt, 1, 8) = #{nowDate}
]]>
</select>

<!-- 웹로그 리스트 -->
<select id="selectWebLogList" resultType="egovMap">
    <![CDATA[
    SELECT * FROM
    (
    SELECT
        row_number() over (order by seq asc) as num,
        row_number() over (order by seq desc) as paging_num, seq, user_id, ip, 
        reg_dt, user_url, user_referer, user_agent, etc
    FROM
       th_web_log
    WHERE
        substr(reg_dt, 1, 8) = #{nowDate}
    ORDER BY
        seq desc
    ) WHERE paging_num > #{firstIndex} and paging_num <= #{recordCountPerPage}
    ]]> 
</select>

 

 

:: Jsp

 

<%@ taglib prefix="ui" uri="http://egovframework.gov/ctl/ui"%>
<%@ taglib prefix="form"   uri="http://www.springframework.org/tags/form" %>

<!-- /Javascript -->
<script type="text/javascript">
function linkPage(pageNo) {
	$("#formWebLog [name='currentPageNo']").val(pageNo);
	$("#formWebLog").submit();
}
</script>

<!-- /Jsp HTML -->
<c:choose>
	<c:when test="${fn:length(webLogList) == 0 }">
		조회결과가 없습니다.
		<br/>
	</c:when>
	<c:otherwise>
	<div style="width:1200px;">
		<table class="table" style="width:100%;table-layout:fixed;word-break:break-all;">
			<thead class="thead-dark">
				<tr>
					<th scope="col" style="width: 8%;">번호</th>
					<th scope="col" style="width: 10%;">사용자</th>
					<th scope="col" style="width: 15%;">IP</th>
					<th scope="col" style="width: 21%;">주소</th>
					<th scope="col" style="width: 21%;">이전주소</th>
					<th scope="col" style="width: 5%;">정보1</th>
					<th scope="col" style="width: 20%;">정보2</th>
					<th scope="col" style="width: 18%;">발생일자</th>
				</tr>
			</thead>
			<tbody>
			<c:forEach var="item" items="${webLogList}">	
				<tr>
					<td>${item.num}</td>
					<td>${item.userId}</td>
					<td>${item.ip}</td>
					<td>${item.userUrl}</td>
					<td>${item.userReferer}</td>
					<td>${item.userAgent}</td>
					<td>${item.etc}</td>
					<td>${item.regDt}</td>
				</tr>
			</c:forEach>
			</tbody>
		</table>
	</div>
	</c:otherwise>
</c:choose>

<!-- /Jsp Pagination -->
<ui:pagination paginationInfo="${paginationInfo}" type="image" jsFunction="linkPage" />

 

 

출처 - https://alisyabob.tistory.com/243

 

728x90