ページングパッケージユーティリティクラスとその使用方法

6084 ワード

ページングパッケージユーティリティクラスとその使用方法
作者:javaboy 2012 Email:[email protected] qq:1046011462
 
 
package com.yanek.util;



import java.util.List;



public class PageBean {



	/**

	 * @param args

	 */

	public static void main(String[] args) {



	}



	private int currentpage; //  

	private int pagesize; //  

	private int totalPagecount; //  

	private int totalRecordCount; //  

	private List recordContents; //  



	public int getCurrentpage() {

		return currentpage;

	}



	public int getPagesize() {

		return pagesize;

	}



	public List getRecordContents() {

		return recordContents;

	}



	public int getTotalPagecount() {

		return totalPagecount;

	}



	public int getTotalRecordCount() {

		return totalRecordCount;

	}



	public PageBean(int currentpage, int pagesize, int totalRecordCount, List recordContents) {

		super();

		this.currentpage = currentpage;

		this.pagesize = pagesize;

		this.totalRecordCount = totalRecordCount;

		this.recordContents = recordContents;



		if (totalRecordCount % pagesize == 0) {

			this.totalPagecount = totalRecordCount / pagesize;

		} else {

			this.totalPagecount = totalRecordCount / pagesize + 1;

		}

	}



}









 :



 action :





	public ActionForward list(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {

		

                TopicDAO tdao=new TopicDAOImpl();



		String s_pagesize=(String)request.getParameter("pagesize");

		int pagesize=20;

		if (s_pagesize!=null)

		{

			pagesize=Integer.parseInt(s_pagesize);

		}

		int pagecount=1;

		String s_pagecount=(String)request.getParameter("pagecount");

		if (s_pagecount!=null)

		{

			pagecount=Integer.parseInt(s_pagecount);

		}

                

                // 		



		long totalcount=tdao.getTopicTotalCount();

		

		

		System.out.println("total:"+totalcount);

		

		List topics=tdao.getTopics(pagesize,pagecount);

		

		for (int i=0;i<topics.size();i++)

		{

			TopicBean tb=(TopicBean)topics.get(i);

			

			System.out.println(tb.getTid()+"-"+tb.getTname());

		}

		

		

		PageBean  pb=new PageBean(pagecount,pagesize, (int)totalcount,topics);



	

		request.setAttribute("topic_pagebean", pb);

		

		return mapping.findForward("topic_list");

	}





jsp :



  <%

  

	    PageBean  pb=(PageBean)request.getAttribute("topic_pagebean");

	    List topics=pb.getRecordContents();

   %>

  



<div class="cont">



<center><h2> </h2></center><br/><br/>

	<div class="list">

	

<form name="topic"  action="topic.do" method="get">





      <input type="hidden" name="method" value="list" />

      <input type="hidden" name="pagesize" value="<%=pb.getPagesize()%>" />





	  <table width="100%" border="0">

        <tr class="white">

          <th class="sl1" width="30%"> </th>

          <th width="30%" class="sl1"> </th>

          <th class="sl1" width="25%">ID </th>

          <th width="15%">  </th>

        </tr>

        

      

      	<% 

      	

      	for (int i=0;i<topics.size();i++)

		{

			TopicBean tb=(TopicBean)topics.get(i);

			%>

	

			<%

			 String classname="";

			 if (i%2==1) 

			 {

			  classname="white";

			 }

		

			%>

			<tr class="<%=classname %>">

	          <td><%=tb.getTname() %></td>

	          <td><%=tb.getTdesc() %></td>

	          <td>

				

				<%=tb.getTid() %>

			  </td>

	          <td><a href='/topic.do?method=view&tid=<%=tb.getTid() %>'>[ ]</a></td>

	        </tr>

			

			

			<%

			

		}

		%>

		

      	

	        

	     	

	        

		

	        <tr>

		<td colspan="6">

		<p align="center">

		<br/>

		

		 <%=pb.getTotalRecordCount() %> , <%=pb.getTotalPagecount() %> , <%=pb.getPagesize() %>  , <%=pb.getCurrentpage() %> 

	

		

		

		 <%

   if (pb.getCurrentpage()==1)

   {

     

     out.print("     ");

   }

   else

   {

     %>

      <a href="topic.do?method=list&pagecount=1&pagesize=<%=pb.getPagesize() %>"> </a>

      <a href="topic.do?method=list&pagecount=<%=pb.getCurrentpage()-1%>&pagesize=<%=pb.getPagesize() %>"> </a>

     <%

     

   }

   %>

   

    <%

   if (pb.getCurrentpage()==pb.getTotalPagecount())

   {

     

     out.print("     ");

   }

   else

   {

     %>

  

  <a href="topic.do?method=list&pagecount=<%=pb.getCurrentpage()+1 %>&pagesize=<%=pb.getPagesize() %>">  </a>

  <a href="topic.do?method=list&pagecount=<%=pb.getTotalPagecount() %>&pagesize=<%=pb.getPagesize() %>">   </a>

     <%

     

   }

   %> 

		

		

		

		  <input type="text" name="pagecount" value="<%=pb.getCurrentpage() %>" size="4">  

		

		 <input type="submit" value="GO" size="4">

		

		</td>

	</tr>

	

	   

		

	

	

      </table></form>

	  

	 

  </div>

</div>





action 



<action path="/topic" type="com.myweb.web.action.TopicAction" scope="request"  parameter="method">

			<forward name="topic_list" path="/WEB-INF/pages/test/test/topic_list.jsp"/>

</action>



 : http://192.168.0.1/topic.do?method=list&pagecount=1&pagesize=10