ページングtest

3832 ワード


/**
 * 
 * @author lan
 *
 */
public class PagerViewTest {
	public static void main(String[] args) {
		int vn=5;// 
		int tp=11;// 
		int pn=4;// 
		int startn=1;// 
		int endn=1;// 
		for(pn=1;pn<=11;pn++){
			if(tp<=vn){// 
				System.out.print("help0");
				startn=1;
				endn=tp;
			}else{// 
					if((pn-vn/2)<=0){// 
						System.out.print("help2");
						startn=1;
						endn=startn+vn-1;
					}else if(tp<pn+vn/2+(vn%2)){// 
						System.out.print("help3");
						startn=tp-vn+1;
						endn=tp;
					}else{// 
						System.out.print("help4");
						startn=(pn-vn/2);
						endn=pn+vn/2-1+(vn%2);
					}
			}
			System.out.print("[ 1]"+"\t");
			for(int i=0;i<(endn-startn+1);i++){
				if(pn==startn+i){
					System.out.print("【"+(startn+i)+"】\t");
				}else{
					System.out.print((startn+i)+"\t");
				}
			}
			System.out.println("[ "+tp+"]");
		}
	}
}


<%@ tag pageEncoding="UTF-8" %>
<%@ include file="/WEB-INF/jsp/common/global.jsp" %>

<%@ attribute name="id" required="true" type="java.lang.String" %>
<%@ attribute name="pager" required="true" type="org.xxx.Pager" %>
<c:set var="tp" value="${pager.totalPage}"/>
<c:set var="pn" value="${pager.pageNumber>pager.totalPage?pager.totalPage:pager.pageNumber}"/>
<c:set var="vn" value="8"/>
<c:set var="startn" value="1"/>
<c:set var="endn" value="1"/>
<c:choose>
	<c:when test="${tp<=vn}">
		<c:set var="startn" value="1"/>
		<c:set var="endn" value="${tp}"/>
	</c:when>
	<c:otherwise>
		<c:choose>
			<c:when test="${pn<=vn/2+(vn%2)}">
				<c:set var="startn" value="1"/>
				<c:set var="endn" value="${startn+vn-1}"/>
			</c:when>
			<c:when test="${tp<pn+vn/2+(vn%2)}">
				<c:set var="startn" value="${tp-vn+1}"/>
				<c:set var="endn" value="${tp}"/>
			</c:when>
			<c:otherwise>
				<c:set var="startn" value="${(pn-vn/2+(vn%2))}"/>
				<c:set var="endn" value="${startn+vn-1}"/>
			</c:otherwise>
		</c:choose>
	</c:otherwise>
</c:choose>
<h2>
<a href="${BASE}/articles/1"> </a>
<c:if test="${pn>1}">
<a href="${BASE}/articles/${pn-1}"> </a>
</c:if>
<c:forEach var="i" begin="${startn}" end="${endn}">
	<c:choose>
		<c:when test="${pn==i}">
			<a href="${BASE}/articles/${i}">【${i}】</a>
		</c:when>
		<c:otherwise>
			<a href="${BASE}/articles/${i}">${i}</a>
		</c:otherwise>
	</c:choose>
</c:forEach>
<c:if test="${pn<tp}">
<a href="${BASE}/articles/${pn+1}"> </a>
</c:if>
<a href="${BASE}/articles/${tp}"> </a>
</h4>
<hr/>