有什么做衣服的网站好,麓谷网站建设公司,龙岩网站建设设计服务,做特价的网站分页的基类import java.util.List;/*** 分页显示的标准类,基本操作,是先给予-当前页数一共的数据条数-每页显示的条数,* 然后在初始化该类,得到总共页数,和开始序号和结束序号,* 然后数据库分页用到开始序号和结束序号,得到数据集合后赋值给该类的list属性,** 然后把该类发送到…分页的基类import java.util.List;/*** 分页显示的标准类,基本操作,是先给予-当前页数一共的数据条数-每页显示的条数,* 然后在初始化该类,得到总共页数,和开始序号和结束序号,* 然后数据库分页用到开始序号和结束序号,得到数据集合后赋值给该类的list属性,** 然后把该类发送到jsp页面,进行访问* author admin** param */public class PageBean {private int pageIndex;//当前页数private int pageSize;//一共的页数private int count;//数据条数private int pageCount;//每页的数据条数private int start;//起始数据位置private int end;//结束private List listnull;public void init(){/*根count 和pageCount计算页数pageSize*/int pageSize_x(int)count/pageCount;if(countpageCount){this.pageSizecount%pageCount0?pageSize_x:pageSize_x1;} else{this.pageSize1;}//判断页数和当前页数if(pageIndexpageSize){pageIndexpageSize;}if(pageIndex1){pageIndex1;}//根据当前页计算起始和结束条目this.start(pageIndex-1)*pageCount1;this.endpageIndex*pageCount;}public PageBean(int pageIndex, int count, int pageCount) {super();this.pageIndex pageIndex;this.count count;this.pageCount pageCount;}public PageBean(int pageIndex, int count, int pageCount, List list) {super();this.pageIndex pageIndex;this.count count;this.pageCount pageCount;this.list list;}public PageBean() {super();// TODO Auto-generated constructor stub}Overridepublic String toString() {return PageBean [count count , end end , list list , pageCount pageCount , pageIndex pageIndex , pageSize pageSize , start start ];}public int getPageIndex() {return pageIndex;}public void setPageIndex(int pageIndex) {this.pageIndex pageIndex;}public int getPageSize() {return pageSize;}public void setPageSize(int pageSize) {this.pageSize pageSize;}public int getCount() {return count;}public void setCount(int count) {this.count count;}public int getPageCount() {return pageCount;}public void setPageCount(int pageCount) {this.pageCount pageCount;}public int getStart() {return start;}public void setStart(int start) {this.start start;}public int getEnd() {return end;}public void setEnd(int end) {this.end end;}public List getList() {return list;}public void setList(List list) {this.list list;}}servlet调用import java.io.IOException;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import com.dao.MessageDao;import com.dao.impl.MessageDaoImpl;import com.vo.Message;import com.vo.PageBean;public class ShowMessageServlet extends HttpServlet{/****/private static final long serialVersionUID 6646899131087204214L;Overrideprotected void doPost(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {doGet(req, resp);}Overrideprotected void doGet(HttpServletRequest req, HttpServletResponse resp)throws ServletException, IOException {req.setCharacterEncoding(UTF-8);resp.setContentType(text/html;charsetutf-8);int pageIndex0;MessageDao mdnew MessageDaoImpl();String pageIndexStrreq.getParameter(pageIndex);if(pageIndexStr!null){try{pageIndexInteger.parseint(pageIndexStr);}catch (Exception e) {}}PageBean pbnew PageBean(pageIndex,md.getMessageCount(),10);pb.init();pb.setList(md.getMessageListOfPage(pb.getStart(), pb.getEnd()));req.setAttribute(pagebean, pb);req.getRequestDispatcher(index.jsp).forward(req, resp);}}jsp页面的显示调用String path request.getContextPath();String basePath request.getScheme()://request.getServerName():request.getServerPort()path/;%My JSP index.jsp starting page${message.title } ${message.editdate }下一个[${pagebean.pageIndex }/${pagebean.pageSize}]总结以上就是本文关于一个通用的Java分页基类代码详解的全部内容希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他Java相关专题如有不足之处欢迎留言指出。感谢朋友们对本站的支持