A classe base de paginação
import java.util.List;/** * The standard class for pagination display is to first give - the total number of data strips in the current page - the number of pieces displayed on each page, * Then, initialize the class to get the total number of pages, the start number and the end number, * Then the database pagination uses the start number and the end number, and then assign it to the list attribute of the class after obtaining the data set, * * Then send the class to the página jsp para acesso * @author admin * * @param <t> */public classe PageBean <t> {private int PageIndex; // páginas atuais private int PageSize; // Número total de páginas privadas int contagem; // ÍNDO DE DADOS DE DADOS PRIVADO INT PAGCOUNT; contagem e pageCount Calcule a contagem de páginas PageSize */int PAGESIZE_X = (int) contagem/pageCount; if (count> = pageCount) {this.pagesize = count%pageCount == 0? Pagesize_x: Pagesize_x+1;} mais {this.pagesize = 1;} // Jude o número de páginas e o número de páginas e o número atual. if (PageIndex> Pagesize) {PageIndex = Pagesize;} if (PageIndex <1) {PageIndex = 1;} // Calcule as entradas de início e final com base na página atual. PageIndex; this.count = count; this.pageCount = pageCount;} public PageBean (Int PageIndex, int count, int pageCount, list <t> list) {super (); this.pageIndex = PageIndex; this.count = count; stub} @Override public String tostring () {return "PageBean [count =" + count + ", end =" + end + ", list =" + list + ", pageCount =" + PageCount + ", PageIndex =" + PageIndex + ", PageSize =" + Pagesize + ", start =" + "" "; setPageIndex (int PageIndex) {this.PageIndex = PageIndex;} public int getPagesize () {retorna Pagesize;} public void setPagesize (int Pagesize) {this.Pagesize integrCount (Pagestize;} public intCount () {Return count; pageCount;} public void setPageCount (int pageCount) {this.pageCount = PagEcount;} public int getStart () {return start;} public void setStart (int start) {this.start = start;} public int getnd () {return end;} public void setEnd (Int end) {{). list;} public void setList (list <t> list) {this.list = list;}}Chamada de servlet
importar java.io.ioException; importar javax.servlet.servletexception; importar javax.servlet.http.httpServlet; importar javax.servlet.http.httpServLeveLeQuest; import javax.servlet.http.HoStletResFonsOnspon; com.dao.impl.messagedaoImpl; import com.vo.message; importar com.vo.pageBean; public class ShowMessageServlet estende httpServlet {/** * */private estático final serialversion HttpServletResponse resp) lança servleTexception, ioexception {doget (req, resp);}@substituir o void protegido doget (httpServletRequest req, httpServletResponse resp) lança servleTexception, ioexception {req.setcharacterencoding ("utf-8"); resp.setContentType ("text/html; charset = utf-8"); int PageIndex = 0; MessAgedao MD = new MessagedAoImpl (); String; PageIndexstr = req.getParameter ("PageIndex"); if (PageIndexstr! = NULL) {Try {PageIndex = Integer.ParseInt (PageIndexstr);} Catch (Exceção e) {}} PageBean <ssage> pb = novo PageBean <ssage> (PageIndex, md.getMessageCount (), 10); pb.init (); pb.setList (md.getMessagelistOfPage (pb.getstart (), pb.getEnd ()); resp);}}A chamada de exibição da página JSP
<%@ Page Language = "java" import = "java.util. uri = "http://java.sun.com/jsp/jstl/core" prefix = "c"%> <! Doctype html public "-// w3c // dtd html 4.01 transitional //"> <html> <weeft> <base hrefath "%= bash = bash) 'Index.jsp' página de partida </itit> <meta http-equiv = "Pragma" content = "no-cache"> <meta http-equiv = "cache-control" content = "no-cache"> <meta http-mequiv = "expires" content = "0"> <meta http-alpela <meta http-equiv = "description" content = "Esta é a minha página"> <!-<link rel = "stylesheet" type = "text/css" href = "styles.css" rel = "Nofollow">-> </head> <c: se test = "$ {PageBean}"> <jsp: <Body> <c: foreach var = "message" itens = "$ {pagebean.list}"> $ {message.title} $ {message.editdate} <br/> </c: foreach> <a href = "showmessage? > Próximo </a> [$ {PageBean.PageIndex} <Bla>/</span> $ {PageBean.Pagesize}] </body> </html>Resumir
O exposto acima é toda a explicação detalhada de um código de classe de base de paginação em java em Java neste artigo, espero que seja útil para todos. Os amigos interessados podem continuar se referindo a outros tópicos relacionados a Java neste site. Se houver alguma falha, deixe uma mensagem para apontá -la. Obrigado amigos pelo seu apoio para este site!