JSP 페이지 나누기 기술 오리지널, 테스트 OK, 데이터베이스에 얼마나 많은 데이터가 있든지 간에 마음껏 펼칠 수 있습니다!

<span style="font-family: Arial, Helvetica, sans-serif;">package accp.hhs.util;</span>
public class PageMoed {
	private int currentIndex; //   
	private int rowSize; //   
	private int sunPage; //   
	private int beginRow; //   
	private int startIndex; //     
	private String order; //  
	
	
	public String getOrder() {
		return order;
	}
	public void setOrder(String order) {
		this.order = order;
	}
	/**
	 *       
	 * @return
	 */
	public int getStartIndex() {
		for(int i=1;i<=this.getSunPage();i+=8){
			if(this.getCurrentIndex()>=i&&this.getCurrentIndex()<i+9){
				startIndex=i;
				break;
		}
		}
		return startIndex;
	}
/**
 *     
 * @return
 */
	public int getBeginRow() {
		//   ,     -1*   
		beginRow=(currentIndex-1)*rowSize;
		return beginRow;
	}
	public void setBeginRow(int beginRow) {
		this.beginRow = beginRow;
	}
	
	
	public int getSunPage() {
	return sunPage;
	}
	
	//   
	public void setSunPage(int sunRow) {
	int temp=0;
	temp=(sunRow%this.getRowSize()==0)?sunRow/this.getRowSize():sunRow/this.getRowSize()+1;
	System.out.println("   :  "+temp+"    :"+this.getRowSize());	
	this.sunPage=temp;
	}
	
	
	
	/**
	 *    
	 * @return
	 */
	public int getCurrentIndex() {
		return currentIndex;
	}
	
	
	public void setCurrentIndex(String currentIndex) {
		//    =1
		if("".equals(currentIndex)||null==currentIndex||!IsNum.isNum(currentIndex)){
			currentIndex="1";
		}
		int currentIndexs=Integer.parseInt(currentIndex);
		//          
		if(currentIndexs>=this.getSunPage()){
			currentIndexs=this.getSunPage();
		}
		
		if(currentIndexs<=0){
			currentIndexs=1;
		}
		this.currentIndex = currentIndexs;
	}
	
	/**
	 *      
	 * @return
	 */
	public int getRowSize() {
		if(rowSize<=0){
			rowSize=2;			
		}
		return rowSize;
	}
	public void setRowSize(int rowSize) {
		this.rowSize = rowSize;
	}
	

}
</pre><p>JSP        ,  OK,          ,      !</p><p>        !       ,      ,        !          。。。。。。。。</p><p>           </p><p></p><pre name="code" class="html"><div>
    <p>
    <a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${currentIndex-1}">
              </a>  
            【${currentIndex}/${totalPage}】
    <c:forEach var="i" begin="${satrtIndex}" end="${satrtIndex+9}">
      
    <a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${i}">
    <c:if test="${currentIndex==i}"> <font color='red'> ${i} </font> </c:if>
    <c:if test="${currentIndex!=i}">${i} </c:if>
    </a>
      
    </c:forEach>
      
    <a href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex=${currentIndex+1}">
            </a>
      
    <input type="text" size="2" id="valuePage"/> 
       
    <a href="javascript:PageIndex()">  </a>   
    </p>
    <%--     --%>
    <script type="text/javascript">
    function PageIndex(){
    var pagev=document.getElementById("valuePage");
    location.href="${pageContext.request.contextPath}/EmpSerive.do?flag=showEmp¤tIndex="+pagev.value;
    } 
    </script>
    </div>

그래!실현류의 방법도 붙여라. 알아볼 수 없으면 나를 탓하지 마라. 왜냐하면 나는 테스트를 할 때 반사 메커니즘을 사용했기 때문에 내가 한 번에 알아볼 수 없게 한다!하하, 네가 필요로 하는 것을 보면 돼..
/**
     *   hql  
     */
	@Override
	public List<T> getPage(String hql, Object[] paramters, PageMoed pageMeod) {
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		
		if(paramters!=null){
		for(int i=0;i<paramters.length;i++){
		query.setParameter(i,paramters[i]);		
		}
		}
		query.setFirstResult(pageMeod.getBeginRow()).setMaxResults(pageMeod.getRowSize());
		
		return (List<T>)query.list();
	}

	/**
	 *       
	 */
	@Override
	public List<T> getPage(T e, PageMoed pageMeod) throws Exception {
		Class cla=e.getClass();
		String tableName=cla.getSimpleName();
		Field[] field=cla.getDeclaredFields();//      
		//SQL    
		StringBuffer sb=new StringBuffer();
		sb.append(" where 1=1 ");
		//List<Object> listValue=new ArrayList<Object>();
		//?   
		for(int i=0;i<field.length;i++){
			Field f=field[i]; 
			f.setAccessible(true);
			Object obj=f.get(e); //      
			
			if(obj instanceof Set){
				System.out.println("   Set.....");
				((Set) obj).clear();
			}else
			//  ?   
			if(!"".equals(obj)&&null!=obj){//       
				sb.append(" and "+f.getName()+"= "+obj);				
				//listValue.add(obj);
			}
		    }
		//       
		if(pageMeod.getOrder()!=null){
			sb.append(" "+pageMeod.getOrder());
		}
		String hql="from "+tableName+" "+sb.toString();
		System.out.println("HQL: "+hql);
		Query query=sessionFactory.getCurrentSession().createQuery(hql);
		//  
		List<T> liste=(List<T>)query.setFirstResult(pageMeod.getBeginRow()).setMaxResults(pageMeod.getRowSize()).list();
		//   
		return liste;
		
	}
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">
</pre><pre name="code" class="html">

좋은 웹페이지 즐겨찾기