java分页

来源:互联网 发布:seo搜索优化软件 编辑:程序博客网 时间:2024/06/15 16:17

entity:

package com.mlnx.base.entity;import java.io.Serializable;import java.util.List;/** * 页面分页类 *  * @author Roy *  */public class PageUtil implements Serializable {private static final long serialVersionUID = 1L;private int curPage;// 当前页private int tolPage;// 总页数private int pageSize = 2;// 一页多少条private int tolRecord;// 总数private List<TApp> app;public List<TApp> getApp() {return app;}public void setApp(List<TApp> app) {this.app = app;}public void countTolPage(int record) {this.tolRecord = record;if (this.tolRecord % this.pageSize == 0) {this.tolPage = this.tolRecord / this.pageSize;} else if (this.tolRecord < this.pageSize) {this.tolPage = 1;} else {this.tolPage = this.tolRecord / this.pageSize + 1;}}public int getCurPage() {return curPage;}public void setCurPage(int curPage) {this.curPage = curPage;}public int getTolPage() {return tolPage;}public void setTolPage(int tolPage) {this.tolPage = tolPage;}public int getPageSize() {return pageSize;}public void setPageSize(int pageSize) {this.pageSize = pageSize;}public int getTolRecord() {return tolRecord;}public void setTolRecord(int tolRecord) {this.tolRecord = tolRecord;}}
col:<pre class="html" name="code">public class PageCol {@Autowired private AppServise appServise;@RequestMapping(value ="firstPage")public ModelAndView getFirstPage(HttpServletRequest request){PageUtil pu=new PageUtil();int record=appServise.countTolNum();pu.setTolRecord(record);pu.countTolPage(record);pu.setCurPage(1);pu.setApp(appServise.findTappByLimit(0, pu.getPageSize()));ModelAndView mav=new ModelAndView("hello");mav.addObject("pu", pu);return mav;}}
页面:
<%@ page language="java" contentType="text/html; charset=utf-8"    pageEncoding="utf-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%><!DOCTYPE html><html><head><title>分页测试</title></head><body><table><c:forEach items="${pu.app}" var="app"><tr><td>${app.id}</td><td>${app.name}</td><td>${app.version}</td><td>${app.stable}</td><td>${app.date}></td><td>${app.path}</td></tr></c:forEach> </table>  <a href="firstPage">首页</a>  <a href ="lastPge?curPage=${pu.curPage}">上一页</a>  <a href ="nextPge?curPage=${pu.curPage}">下一页</a>  <a href ="endPge?curPage=${pu.curPage}">尾页</a>  第${pu.curPage}页/共${pu.tolPage}>页 </body></html>

0 0
原创粉丝点击