关于分页Pagination的使用
Posted limn
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了关于分页Pagination的使用相关的知识,希望对你有一定的参考价值。
在这个例子当中,用的是ssm框架整合,并且用的是Pagination实现分页
先来看一下分页中用到的类的源码
Paginable.java
1 package cn.itcast.common.page; 2 3 /** 4 * 分页接口 5 */ 6 public interface Paginable { 7 /** 8 * 总记录数 9 * 10 * @return 11 */ 12 public int getTotalCount(); 13 14 /** 15 * 总页数 16 * 17 * @return 18 */ 19 public int getTotalPage(); 20 21 /** 22 * 每页记录数 23 * 24 * @return 25 */ 26 public int getPageSize(); 27 28 /** 29 * 当前页号 30 * 31 * @return 32 */ 33 public int getPageNo(); 34 35 /** 36 * 是否第一页 37 * 38 * @return 39 */ 40 public boolean isFirstPage(); 41 42 /** 43 * 是否最后一页 44 * 45 * @return 46 */ 47 public boolean isLastPage(); 48 49 /** 50 * 返回下页的页号 51 */ 52 public int getNextPage(); 53 54 /** 55 * 返回上页的页号 56 */ 57 public int getPrePage(); 58 }
Pagination.java
1 package cn.itcast.common.page; 2 3 import java.util.ArrayList; 4 import java.util.List; 5 6 /** 7 * 列表分页。包含list属性。 8 */ 9 public class Pagination extends SimplePage{ 10 11 public Pagination() { 12 } 13 14 /** 15 * 构造器 16 * 17 * @param pageNo 18 * 页码 19 * @param pageSize 20 * 每页几条数据 21 * @param totalCount 22 * 总共几条数据 23 */ 24 public Pagination(int pageNo, int pageSize, int totalCount) { 25 super(pageNo, pageSize, totalCount); 26 27 } 28 29 /** 30 * 构造器 31 * 32 * @param pageNo 33 * 页码 34 * @param pageSize 35 * 每页几条数据 36 * @param totalCount 37 * 总共几条数据 38 * @param list 39 * 分页内容 40 */ 41 public Pagination(int pageNo, int pageSize, int totalCount, List<?> list) { 42 super(pageNo, pageSize, totalCount); 43 this.list = list; 44 } 45 46 /** 47 * 第一条数据位置 48 * 49 * @return 50 */ 51 public int getFirstResult() { 52 return (pageNo - 1) * pageSize; 53 } 54 55 /** 56 * 当前页的数据 57 */ 58 private List<?> list; 59 60 /** 61 * 当前页的分页样式 62 */ 63 private List<String> pageView; 64 65 /** 66 * 获得分页内容 67 * 68 * @return 69 */ 70 public List<?> getList() { 71 return list; 72 } 73 74 /** 75 * 设置分页内容 76 * 77 * @param list 78 */ 79 @SuppressWarnings("unchecked") 80 public void setList(List list) { 81 this.list = list; 82 } 83 /** 84 * 获得分页样式 85 * 86 * @return 87 */ 88 public List<String> getPageView() { 89 return pageView; 90 } 91 /** 92 * 设置分页样式 93 * 94 * @param list 95 */ 96 public void setPageView(List<String> pageView) { 97 this.pageView = pageView; 98 } 99 100 101 /** 102 * 分页显示样示部分 103 */ 104 public void pageView(String url,String params){ 105 106 pageView = new ArrayList<String>(); 107 108 if(this.pageNo != 1){ 109 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo=1‘"><font size=2>首页</font></a>"); 110 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo-1)+"‘"><font size=2>上一页</font></a>"); 111 }else{ 112 pageView.add("<font size=2>首页</font>"); 113 pageView.add("<font size=2>上一页</font>"); 114 } 115 116 if(this.getTotalPage() <= 10){ 117 for (int i = 0; i < this.getTotalPage(); i++) { 118 if((i+1)==this.pageNo){ 119 pageView.add("<strong>"+this.pageNo+"</strong>"); 120 i = i+1; 121 if(this.pageNo==this.getTotalPage())break; 122 } 123 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i+1)+"‘">"+(i+1)+"</a>"); 124 } 125 }else if(this.getTotalPage() <= 20){ 126 //没有把...加上 127 int l = 0; 128 int r = 0; 129 if(this.pageNo<5){ 130 l=this.pageNo-1; 131 r=10-l-1; 132 }else if(this.getTotalPage()-this.pageNo<5){ 133 r=this.getTotalPage()-this.pageNo; 134 l=10-1-r; 135 }else{ 136 l=4; 137 r=5; 138 } 139 int tmp = this.pageNo-l; 140 for (int i = tmp; i < tmp+10; i++) { 141 if(i==this.pageNo){ 142 pageView.add("<strong>"+this.pageNo+"</strong>"); 143 i = i+1; 144 if(this.pageNo==this.getTotalPage()) break; 145 } 146 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i)+"‘">"+(i)+"</a>"); 147 } 148 149 }else if(this.pageNo<7){ 150 for (int i = 0; i < 8; i++) { 151 if(i+1==this.pageNo){ 152 pageView.add("<strong>"+this.pageNo+"</strong>"); 153 i = i+1; 154 } 155 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i+1)+"‘">"+(i+1)+"</a>"); 156 } 157 pageView.add("..."); 158 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage()-1)+"‘">"+(this.getTotalPage()-1)+"</a>"); 159 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage())+"‘">"+(this.getTotalPage())+"</a>"); 160 }else if(this.pageNo>this.getTotalPage()-6){ 161 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(1)+"‘">"+(1)+"</a>"); 162 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(2)+"‘">"+(2)+"</a>"); 163 pageView.add("..."); 164 for (int i = this.getTotalPage()-8; i <this.getTotalPage() ; i++) { 165 if(i+1==this.pageNo){ 166 pageView.add("<strong>"+this.pageNo+"</strong>"); 167 i = i+1; 168 if(this.pageNo==this.getTotalPage()) break; 169 } 170 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i+1)+"‘">"+(i+1)+"</a>"); 171 } 172 }else{ 173 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(1)+"‘">"+(1)+"</a>"); 174 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(2)+"‘">"+(2)+"</a>"); 175 pageView.add("..."); 176 177 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo-2)+"‘">"+(this.pageNo-2)+"</a>"); 178 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo-1)+"‘">"+(this.pageNo-1)+"</a>"); 179 pageView.add("<strong>"+this.pageNo+"</strong>"); 180 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo+1)+"‘">"+(this.pageNo+1)+"</a>"); 181 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo+2)+"‘">"+(this.pageNo+2)+"</a>"); 182 183 pageView.add("..."); 184 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage()-1)+"‘">"+(this.getTotalPage()-1)+"</a>"); 185 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage())+"‘">"+(this.getTotalPage())+"</a>"); 186 } 187 if(this.pageNo != this.getTotalPage()){ 188 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo+1)+"‘"><font size=2>下一页</font></a>"); 189 pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+this.getTotalPage()+"‘"><font size=2>尾页</font></a>"); 190 } else{ 191 pageView.add("<font size=2>下一页</font>"); 192 pageView.add("<font size=2>尾页</font>"); 193 } 194 pageView.add("共<var>" + getTotalPage() + "</var>页 到第<input type=‘text‘ id=‘PAGENO‘ size=‘3‘ />页 <input type=‘button‘ id=‘skip‘ class=‘hand btn60x20‘ value=‘确定‘ onclick="javascript:window.location.href = ‘" + url + "?" + params + "&pageNo=‘ + $(‘#PAGENO‘).val() "/>"); 195 } 196 }
SimplePage.java
1 package cn.itcast.common.page; 2 3 /** 4 * 简单分页类 5 */ 6 public class SimplePage implements java.io.Serializable,Paginable { 7 8 private static final long serialVersionUID = 1L; 9 public static final int DEF_COUNT = 20; 10 11 /** 12 * 检查页码 checkPageNo 13 * 14 * @param pageNo 15 * @return if pageNo==null or pageNo<1 then return 1 else return pageNo 16 */ 17 public static int cpn(Integer pageNo) { 18 return (pageNo == null || pageNo < 1) ? 1 : pageNo; 19 } 20 21 public SimplePage() { 22 } 23 24 /** 25 * 构造器 26 * 27 * @param pageNo 28 * 页码 29 * @param pageSize 30 * 每页几条数据 31 * @param totalCount 32 * 总共几条数据 33 */ 34 public SimplePage(int pageNo, int pageSize, int totalCount) { 35 setTotalCount(totalCount); 36 setPageSize(pageSize); 37 setPageNo(pageNo); 38 adjustPageNo(); 39 40 } 41 42 /** 43 * 调整页码,使不超过最大页数 44 */ 45 public void adjustPageNo() { 46 if (pageNo == 1) { 47 return; 48 } 49 int tp = getTotalPage(); 50 if (pageNo > tp) { 51 pageNo = tp; 52 } 53 } 54 55 /** 56 * 获得页码 57 */ 58 public int getPageNo() { 59 return pageNo; 60 } 61 62 /** 63 * 每页几条数据 64 */ 65 public int getPageSize() { 66 return pageSize; 67 } 68 69 /** 70 * 总共几条数据 71 */ 72 public int getTotalCount() { 73 return totalCount; 74 } 75 76 /** 77 * 总共几页 78 */ 79 public int getTotalPage() { 80 int totalPage = totalCount / pageSize; 81 if (totalPage == 0 || totalCount % pageSize != 0) { 82 totalPage++; 83 } 84 return totalPage; 85 } 86 87 /** 88 * 是否第一页 89 */ 90 public boolean isFirstPage() { 91 return pageNo <= 1; 92 } 93 94 /** 95 * 是否最后一页 96 */ 97 public boolean isLastPage() { 98 return pageNo >= getTotalPage(); 99 } 100 101 /** 102 * 下一页页码 103 */ 104 public int getNextPage() { 105 if (isLastPage()) { 106 return pageNo; 107 } else { 108 return pageNo + 1; 109 } 110 } 111 112 /** 113 * 上一页页码 114 */ 115 public int getPrePage() { 116 if (isFirstPage()) { 117 return pageNo; 118 } else { 119 return pageNo - 1; 120 } 121 } 122 123 protected int totalCount = 0; 124 protected int pageSize = 20; 125 protected int pageNo = 1; 126 127 /** 128 * if totalCount<0 then totalCount=0 129 * 130 * @param totalCount 131 */ 132 public void setTotalCount(int totalCount) { 133 if (totalCount < 0) { 134 this.totalCount = 0; 135 } else { 136 this.totalCount = totalCount; 137 } 138 } 139 140 /** 141 * if pageSize< 1 then pageSize=DEF_COUNT 142 * 143 * @param pageSize 144 */ 145 public void setPageSize(int pageSize) { 146 if (pageSize < 1) { 147 this.pageSize = DEF_COUNT; 148 } else { 149 this.pageSize = pageSize; 150 } 151 } 152 153 /** 154 * if pageNo < 1 then pageNo=1 155 * 156 * @param pageNo 157 */ 158 public void setPageNo(int pageNo) { 159 if (pageNo < 1) { 160 this.pageNo = 1; 161 } else { 162 this.pageNo = pageNo; 163 } 164 } 165 }
好了,下面是我写的项目的源码,用的就是这个Pagination来实现分页
BrandController.java
1 package cn.lzc.code.controller.admin; 2 3 import org.springframework.beans.factory.annotation.Autowired; 4 import org.springframework.stereotype.Controller; 5 import org.springframework.ui.Model; 6 import org.springframework.web.bind.annotation.RequestMapping; 7 8 import cn.itcast.common.page.Pagination; 9 import cn.lzc.code.po.Brand; 10 import cn.lzc.code.service.BrandService; 11 12 /** 13 * 品牌管理Controller 14 * 15 * @author admin 16 * 17 */ 18 @Controller 19 @RequestMapping("/brand") 20 public class BrandController { 21 // 自动装配 22 @Autowired 23 private BrandService brandService; 24 25 /** 26 * 获取 品牌列表,按条件搜索 27 * 28 * @return 29 */ 30 @RequestMapping(value = "list.do") 31 public String list(Integer pageNo, String name, Integer isDisplay, Model model) { 32 // 分页查询品牌,按条件搜索 33 Pagination pagination = brandService.getBrandListByQuery(pageNo, name, isDisplay); 34 // 添加显示到页面 35 model.addAttribute("pagination", pagination); 36 // 回显查询条件name 37 model.addAttribute("name", name); 38 // 回显查询条件isDisplay 39 model.addAttribute("isDisplay", isDisplay); 40 return "brand/list"; 41 } 42 }
BrandService.java
1 package cn.lzc.code.service; 2 3 import java.util.List; 4 5 import cn.itcast.common.page.Pagination; 6 import cn.lzc.code.po.Brand; 7 8 /** 9 * 品牌接口 10 * 11 * @author admin 12 * 13 */ 14 public interface BrandService { 15 /** 16 * 根据条件查询品牌,可分页 17 * 18 * @param pageNo 19 * @param name 20 * @param isDisplay 21 * @return 22 */ 23 public Pagination getBrandListByQuery(Integer pageNo, String name, Integer isDisplay); 24 25 }
BrandServiceImpl.java
1 package cn.lzc.code.service.impl; 2 3 import java.util.List; 4 5 import org.springframework.beans.factory.annotation.Autowired; 6 import org.springframework.stereotype.Service; 7 8 import cn.itcast.common.page.Pagination; 9 import cn.lzc.code.mapper.BrandMapper; 10 import cn.lzc.code.po.Brand; 11 import cn.lzc.code.po.vo.BrandQuery; 12 import cn.lzc.code.service.BrandService; 13 14 /** 15 * 品牌管理实现类 16 * 17 * @author admin 18 * 19 */ 20 @Service 21 public class BrandServiceImpl implements BrandService { 22 // 自动装配 23 @Autowired 24 private BrandMapper brandMapper; 25 26 /** 27 * 根据条件查询品牌,可分页 28 */ 29 public Pagination getBrandListByQuery(Integer pageNo, String name, Integer isDisplay) { 30 // 如果传入的是字符串,那就是null 31 if (name != null) 32 if ("".equals(name.trim())) { 33 name = null; 34 } 35 // 创建一个传递参数的品牌查询 36 BrandQuery brandQuery = new BrandQuery(); 37 // 设置查询品牌可见的,1为可见,0为不可见 38 brandQuery.setIsDisplay(1); 39 40 // 拼接条件,显示url 41 StringBuilder str = new StringBuilder(); 42 if (name != null) { 43 brandQuery.setName(name); 44 str.append("name=").append(name); 45 } 46 if (isDisplay != null) { 47 brandQuery.setIsDisplay(isDisplay); 48 str.append("&isDisplay=").append(isDisplay); 49 } else { 50 // 设置只能查询 可见的品牌 51 brandQuery.setIsDisplay(1); 52 str.append("&isDisplay=").append(1); 53 } 54 55 // 查询brand的总记录数 56 int totalCount = brandMapper.getBrandCount(brandQuery); 57 58 // cpn方法,如果pageNo<1或为空,则设置为1 59 int pageNo1 = Pagination.cpn(pageNo); 60 61 // 设置开始页 62 brandQuery.setPageNo(pageNo1); 63 64 // 查询品牌总记录 65 List<Brand> brands = brandMapper.getBrandListByQuery(brandQuery); 66 // 构建分页对象 67 // 四个参数,当前页数,每页显示的记录数,总记录数,查询出来的列表也就是要显示的列表 68 Pagination pagination = new Pagination(pageNo1, brandQuery.getPageSize(), totalCount, brands); 69 // 分页在页面显示 /brand/list.do?name=aaa&&isDisplay=1 70 String url = "/brand/list.do"; 71 pagination.pageView(url, str.toString()); 72 73 // 返回分页对象 74 return pagination; 75 } 76 77 }
cpn方法,用来判断当前页pageNo,如果pageNo<1或为空,则设置为1
源码
/** * 检查页码 checkPageNo * * @param pageNo * @return if pageNo==null or pageNo<1 then return 1 else return pageNo */ public static int cpn(Integer pageNo) { return (pageNo == null || pageNo < 1) ? 1 : pageNo; }
BrandMapper.java
1 package cn.lzc.code.mapper; 2 3 import java.util.List; 4 5 import cn.lzc.code.po.Brand; 6 import cn.lzc.code.po.vo.BrandQuery; 7 8 /** 9 * 品牌Mapper 10 * 11 * @author admin 12 * 13 */ 14 public interface BrandMapper { 15 /** 16 * 查询brand的总记录数 17 * @param brandQuery 18 * 19 * @return 20 */ 21 public int getBrandCount(BrandQuery brandQuery); 22 23 /** 24 * 根据条件查询品牌,可分页 25 * 26 * @param brandQuery 27 * @return 28 */ 29 public List<Brand> getBrandListByQuery(BrandQuery brandQuery); 30 31 }
BrandMapper.xml
1 <?xml version="1.0" encoding="UTF-8" ?> 2 <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> 3 4 <!-- 返回结果与javaBean Brand对象中的属性 映射关系 --> 5 <mapper namespace="cn.lzc.code.mapper.BrandMapper"> 6 <resultMap type="cn.lzc.code.po.Brand" id="brand"> 7 <result property="id" column="id" /> 8 <result property="name" column="name" /> 9 <result property="description" column="description" /> 10 <result property="imgUrl" column="img_url" /> 11 <result property="webSite" column="web_site" /> 12 <result property="sort" column="sort" /> 13 <result property="isDisplay" column="is_display" /> 14 </resultMap> 15 16 <!-- 查询品牌总记录数 --> 17 <select id="getBrandCount" parameterType="cn.lzc.code.po.vo.BrandQuery" 18 resultType="Integer"> 19 select 20 count(*) 21 from 22 bbs_brand 23 <where> 24 is_display=#{isDisplay} 25 26 <if test="name !=null"> 27 and name = #{name} 28 </if> 29 </where> 30 </select> 31 32 <!-- 根据条件查询品牌,可分页 --> 33 <select id="getBrandListByQuery" parameterType="cn.lzc.code.po.vo.BrandQuery" 34 resultMap="brand"> 35 select 36 id,name,description,img_url,web_site,sort,is_display 37 from 38 bbs_brand 39 <where> 40 is_display=#{isDisplay} 41 <if test="name !=null"> 42 and name like ‘%${name}%‘ 43 </if> 44 </where> 45 order by id asc 46 limit ${startRow} , ${pageSize} 47 </select> 48 49 </mapper>
jsp页面
<tbody class="pn-ltbody"> <c:forEach items="${pagination.list}" var="brand"> <tr bgcolor="#ffffff" onmouseout="this.bgColor=‘#ffffff‘" onmouseover="this.bgColor=‘#eeeeee‘"> <td> <input type="checkbox" value="${brand.id}" name="ids"/></td> <td align="center">${brand.id }</td> <td align="center">${brand.name }</td> <td align="center"><img width="40" height="40" src="${brand.allImgUrl}"/></td> <td align="center">${brand.description}</td> <td align="center">${brand.sort}</td> <td align="center"> <c:if test="${brand.isDisplay==1}">是</c:if> <c:if test="${brand.isDisplay==0}">否</c:if> </td> <td align="center"> <a class="pn-opt" href="#">修改</a> | <a class="pn-opt" onclick="if(!confirm(‘您确定删除吗?‘)) {return false;}" href="#">删除</a> </td> </tr> </c:forEach> </tbody> <div class="page pb15"> <span class="r inb_a page_b"> <c:forEach items="${pagination.pageView }" var="page"> ${page } </c:forEach> </span> </div>
分页样式显示的样式及部分代码
/** * 分页显示样示部分 */ public void pageView(String url,String params){ pageView = new ArrayList<String>(); if(this.pageNo != 1){ pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo=1‘"><font size=2>首页</font></a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo-1)+"‘"><font size=2>上一页</font></a>"); }else{ pageView.add("<font size=2>首页</font>"); pageView.add("<font size=2>上一页</font>"); } if(this.getTotalPage() <= 10){ for (int i = 0; i < this.getTotalPage(); i++) { if((i+1)==this.pageNo){ pageView.add("<strong>"+this.pageNo+"</strong>"); i = i+1; if(this.pageNo==this.getTotalPage())break; } pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i+1)+"‘">"+(i+1)+"</a>"); } }else if(this.getTotalPage() <= 20){ //没有把...加上 int l = 0; int r = 0; if(this.pageNo<5){ l=this.pageNo-1; r=10-l-1; }else if(this.getTotalPage()-this.pageNo<5){ r=this.getTotalPage()-this.pageNo; l=10-1-r; }else{ l=4; r=5; } int tmp = this.pageNo-l; for (int i = tmp; i < tmp+10; i++) { if(i==this.pageNo){ pageView.add("<strong>"+this.pageNo+"</strong>"); i = i+1; if(this.pageNo==this.getTotalPage()) break; } pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i)+"‘">"+(i)+"</a>"); } }else if(this.pageNo<7){ for (int i = 0; i < 8; i++) { if(i+1==this.pageNo){ pageView.add("<strong>"+this.pageNo+"</strong>"); i = i+1; } pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i+1)+"‘">"+(i+1)+"</a>"); } pageView.add("..."); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage()-1)+"‘">"+(this.getTotalPage()-1)+"</a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage())+"‘">"+(this.getTotalPage())+"</a>"); }else if(this.pageNo>this.getTotalPage()-6){ pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(1)+"‘">"+(1)+"</a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(2)+"‘">"+(2)+"</a>"); pageView.add("..."); for (int i = this.getTotalPage()-8; i <this.getTotalPage() ; i++) { if(i+1==this.pageNo){ pageView.add("<strong>"+this.pageNo+"</strong>"); i = i+1; if(this.pageNo==this.getTotalPage()) break; } pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(i+1)+"‘">"+(i+1)+"</a>"); } }else{ pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(1)+"‘">"+(1)+"</a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(2)+"‘">"+(2)+"</a>"); pageView.add("..."); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo-2)+"‘">"+(this.pageNo-2)+"</a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo-1)+"‘">"+(this.pageNo-1)+"</a>"); pageView.add("<strong>"+this.pageNo+"</strong>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo+1)+"‘">"+(this.pageNo+1)+"</a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo+2)+"‘">"+(this.pageNo+2)+"</a>"); pageView.add("..."); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage()-1)+"‘">"+(this.getTotalPage()-1)+"</a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.getTotalPage())+"‘">"+(this.getTotalPage())+"</a>"); } if(this.pageNo != this.getTotalPage()){ pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+(this.pageNo+1)+"‘"><font size=2>下一页</font></a>"); pageView.add("<a href="javascript:void(0);" onclick="javascript:window.location.href=‘" + url + "?" + params + "&pageNo="+this.getTotalPage()+"‘"><font size=2>尾页</font></a>"); } else{ pageView.add("<font size=2>下一页</font>"); pageView.add("<font size=2>尾页</font>"); } pageView.add("共<var>" + getTotalPage() + "</var>页 到第<input type=‘text‘ id=‘PAGENO‘ size=‘3‘ />页 <input type=‘button‘ id=‘skip‘ class=‘hand btn60x20‘ value=‘确定‘ onclick="javascript:window.location.href = ‘" + url + "?" + params + "&pageNo=‘ + $(‘#PAGENO‘).val() "/>"); }
以上是关于关于分页Pagination的使用的主要内容,如果未能解决你的问题,请参考以下文章