Kelas dasar pagination
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 Halaman JSP untuk akses * @Author admin * * @param <t> */kelas publik PageBean <T> {private int pageIndex; // halaman saat ini Private int halaman; // Jumlah total halaman inter pribadi; init () {/ *root count dan pagecount menghitung halaman jumlah halaman */int pageSize_x = (int) count/pageCount; if (count> = pagecount) {this.pagesize = count%pageCount == 0? PAGESIZE_X: PAGESIZE_X+1;} else {this.pagesize = pagesize_x: pagesze_x+1;} else {this.pagesize = pageSize_x: pagesze_x+1;} else {this if (pageIndex> pageSize) {pageIndex = pageSize;} if (pageIndex <1) {pageIndex = 1;} // Hitung entri Mulai dan Akhir berdasarkan halaman saat ini this.start = (pageIndex-1)*pagecount+1; this.end = pageIndex*pagecount;} pageBeBean PAGEBEBEAN (PAGEBET, INT.EnD = PageIndex*PAGECOUNT;} PageBeBeAN PUBUM PUBLIK (PAGE THIS. {super();this.pageIndex = 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;this.pageCount = pageCount;this.list = list;}public PageBean() {super();// TODO Auto-generated constructor stub}@Override public 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 setPages () {this.pageSize = fageSize;} public int getCounte () {this.pagageSize = fageSize;} public int getCounte () {this.pageSize = fageSize;} public int getCounte () {this.pagageSize = fageSize;} public int getCounte () {this {this.count = count;} public int getPagecount () {return pagecount;} public void setPagecount (int pagecount) {this.pagecount = pagecount pagar;} public int getStart () {return start;} public void setStart (int start) {this.start = start () {return; {this.end = end;} Daftar publik <t> getList () {return list;} public void setList (Daftar <T> Daftar) {this.list = list;}}panggilan servlet
Impor java.io.ioException; impor javax.servlet.servletException; import javax.servlet.http.httpservlet; import javax.servlet.http.httpservletreest; import comes.servlet.http.htpservletequest; com.dao.impl.messagedAImpl; import com.vo.message; import com.vo.pagebean; kelas publik showmessageServlet memperluas httpservlet {/** * */private static long serialversionuid = 664699131087204214l;@eoverrps = 664699131087204214l;@@eoverrps = 664689131087204214l;@eoverrps = 6646899131087204214l;@@@eoverrps = 6646899131087204214L; EXTATION; Httpservletresponse resp) melempar servletException, ioException {doGet (req, resp);}@override void doGet yang dilindungi (httpservletrequest req, httpservletresponse resp) melempar servletException, ioEksepsion {req.setcharacterencoding ("UTF-8"); resp.setContentType ("Teks/html; charset = UTF-8"); int pageIndex = 0; Messageage md = NewsageageOmpl (); string md = new MessageageoImpl (); String) pageIndExstr = req.getParameter ("pageIndex"); if (pageIndexstr! = null) {coba {pageIndex = integer.parseint (pageIndexstr);} catch (Exception e) {}} PageBean <pesage> pb = new = baru PageBean <pesage> (PageIndex, md.getMessageCount (), 10); pb.init (); pb.setlist (md.getMessageListOfpage (pb.getStart (), pb.getend ())); req.setAttribute ("pagebean", pb); req)); req. resp);}}Panggilan tampilan halaman JSP
<%@ page language = "java" import = "java.util.*" pageEncoding = "UTF-8"%> <%string path = request.getContextPath (); string basePath = request.getScheme ()+": //"+request.getServername ()+":"+request.getServerport ()+"+";%;%; "@%() <)+": "+getserverport ()+"+"+"+"+"+") uri="http://java.sun.com/jsp/jstl/core" prefix="c" %><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>" rel="external nofollow" > <title>My JSP 'index.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv = "deskripsi" konten = "ini halaman saya"> <!-<tautan rel = "stylesheet" type = "text/css" href = "styles.css" rel = "eksternal nofollow"> </head> <c: if test = "$ {pageBean {{{{{{Jsp {JSP JSPAGE> </COMPREAGE </COMPREAGE </COMPREAGE </COMPREAGE </COMPREAGE = <body> <c: foreach var = "message" items = "$ {pageBean.list}"> $ {message.title} $ {message.editDate} <br/> </c: foreach> <a href = "showmessage? pageIndex = $ {pageBean.pageindex+1}" Extern "noFlowe" NOFLEX = $ {pageBean.pageindex+1} "Extern" exter "noftole" NOFLEX = "exter" NOFLEABEAN.PAGAGAGININDEX+1} "EXCORE" "EXOCE" NOFAL "NOFAL" > Berikutnya </a> [$ {PageBean.PageIndex} <span>/</span> $ {PageBean.Pagesize}] </body> </html>Meringkaskan
Di atas adalah semua penjelasan terperinci dari kode kelas pagination Java Pagination umum dalam artikel ini, saya harap ini akan membantu semua orang. Teman yang tertarik dapat terus merujuk ke topik terkait Java lainnya di situs web ini. Jika ada kekurangan, silakan tinggalkan pesan untuk menunjukkannya. Terima kasih teman atas dukungan Anda untuk situs ini!