代码语言
.
CSharp
.
JS
Java
Asp.Net
C
MSSQL
PHP
Css
PLSQL
Python
Shell
EBS
ASP
Perl
ObjC
VB.Net
VBS
MYSQL
GO
Delphi
AS
DB2
Domino
Rails
ActionScript
Scala
代码分类
文件
系统
字符串
数据库
网络相关
图形/GUI
多媒体
算法
游戏
Jquery
Extjs
Android
HTML5
菜单
网页交互
WinForm
控件
企业应用
安全与加密
脚本/批处理
开放平台
其它
【
Java
】
bootstrap3分页标签
作者:
life
/ 发布于
2014/9/22
/
697
package com.kerbores.nutz.tag; import java.io.IOException; import java.io.UnsupportedEncodingException; import java.net.URLEncoder; import java.util.Iterator; import java.util.Map; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.TagSupport; import org.nutz.log.Log; import org.nutz.log.Logs; import com.kerbores.nutz.utils.GlobalConst; /** * @author 王贵源 create at 2014年9月20日 下午12:24:16 */ public class Bootstrap3Pagination extends TagSupport { /** * */ private static final long serialVersionUID = 1L; private Log log = Logs.get(); /** * 请求的命名空间 */ private String nameSpace; /** * 请求的方法(路径) */ private String method; /** * 当前页 */ private int page; /** * 分页条最大长度 */ private int maxLength = GlobalConst.MAX_PAGE_BAR_LENGTH; /** * 总页数 */ private int pages; /** * 其他请求参数 */ private Map otherParam; /** * 分页参数名 */ private String pageParam = "page"; /** * 参数的encoding charset */ private String paramEncoding = "UTF-8"; /** * 输出流 */ private JspWriter out; /** * @return the nameSpace */ public String getNameSpace() { return nameSpace; } /** * @param nameSpace * the nameSpace to set */ public void setNameSpace(String nameSpace) { this.nameSpace = nameSpace; } /** * @return the method */ public String getMethod() { return method; } /** * @param method * the method to set */ public void setMethod(String method) { this.method = method; } /** * @return the page */ public int getPage() { return page; } /** * @param page * the page to set */ public void setPage(int page) { this.page = page; } /** * @return the maxLength */ public int getMaxLength() { return maxLength; } /** * @param maxLength * the maxLength to set */ public void setMaxLength(int maxLength) { this.maxLength = maxLength; } /** * @return the pages */ public int getPages() { return pages; } /** * @param pages * the pages to set */ public void setPages(int pages) { this.pages = pages; } /** * @return the otherParam */ public Map getOtherParam() { return otherParam; } /** * @param otherParam * the otherParam to set */ public void setOtherParam(Map otherParam) { this.otherParam = otherParam; } /** * @return the pageParam */ public String getPageParam() { return pageParam; } /** * @param pageParam * the pageParam to set */ public void setPageParam(String pageParam) { this.pageParam = pageParam; } /** * @return the paramEncoding */ public String getParamEncoding() { return paramEncoding; } /** * @param paramEncoding * the paramEncoding to set */ public void setParamEncoding(String paramEncoding) { this.paramEncoding = paramEncoding; } /* * (non-Javadoc) * * @see javax.servlet.jsp.tagext.TagSupport#doStartTag() */ @Override public int doStartTag() throws JspException { out = pageContext.getOut(); return super.doStartTag(); } /* * (non-Javadoc) * * @see javax.servlet.jsp.tagext.TagSupport#doEndTag() */ @Override public int doEndTag() throws JspException { try { out.write(genPager()); } catch (IOException e) { log.warn(e); e.printStackTrace(); } return SKIP_BODY; } /** * 生产分页条 * * @return */ private String genPager() { if (pages == 0) { return ""; } String url = nameSpace + method + "?"; // 处理路径 try { if (otherParam != null) { Iterator it = otherParam.keySet().iterator(); while (it.hasNext()) { String key = it.next().toString(); String val = otherParam.get(key).toString(); url += key + "=" + URLEncoder.encode(val, paramEncoding) + "&"; } } } catch (UnsupportedEncodingException e) { log.warn(e); e.printStackTrace(); } url += pageParam + "="; String bar = "<ul class='pagination pagination-sm fill-inline'>"; bar += "<li " + (page <= 1 ? "class='disabled'" : "") + "><a href='" + url + (page - 1) + "'>«</a></li>"; if (pages < maxLength) { maxLength = pages; } // 页码小于分页条的一半的时候,从第一页开始显示到barLength页//page 1 barLength 2 if (page <= maxLength / 2) { bar += genPagerBarNode(url, 1, maxLength, page); } // 页码大于页数减去分页长度的一半的时候 显示 pages - maxLength到pages页 else if (page >= pages - maxLength / 2) { bar += genPagerBarNode(url, pages - maxLength == 0 ? 1 : pages - maxLength, pages, page); } // 中间情况 显示 page - maxLength/2到page+maxLength/2页 else { bar += genPagerBarNode(url, page - maxLength / 2, page + maxLength / 2, page); } // 处理结尾 bar += "<li " + (page == pages ? "class='disabled'" : "") + "><a href='" + url + (page + 1) + "'>»</a></li>"; bar += "</ul>"; return bar; } /** * * 生成分页节点 * * @param url * 分页URL * @param start * 开始节点index * @param end * 结束节点index * @param page * 当前页 * @return */ private String genPagerBarNode(String url, int start, int end, int page) { String target = ""; for (int i = start; i <= end; i++) { target += "<li " + (page == i ? "class='active'" : "") + "><a href='" + url + i + "'>" + i + (page == i ? "<span class='sr-only'>(current)</span>" : "") + "</a></li>"; } return target; } } index.jsp <%@page import="org.nutz.lang.util.NutMap"%> <%@page import="com.kerbores.utils.entries.Result"%> <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="it" uri="http://ixion.net/tag/it"%> <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <link href="http://cdn.bootcss.com/bootstrap/3.2.0/css/bootstrap.min.css" rel="stylesheet"> <title><c:choose> <c:when test="${empty obj.title }"> 123 </c:when> <c:otherwise> ${obj.title } </c:otherwise> </c:choose></title> </head> <body> sdfgh <% pageContext.setAttribute("base", Result.success()); NutMap map = new NutMap(); map.put("name", "中文名称"); map.put("age", "14"); map.put("id", "4"); %> <it:printer value="abcd" /> <it:pager3 pages="3" nameSpace="a/" page="1" method="aa.do" otherParam="<%=map%>" /> </body> <script src="http://cdn.bootcss.com/jquery/1.11.1/jquery.min.js"></script> <script src="http://cdn.bootcss.com/bootstrap/3.2.0/js/bootstrap.min.js"></script> </html> <?xml version="1.0" encoding="UTF-8"?> <taglib version="2.0" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee web-jsptaglibrary_2_0.xsd"> <description>nutz功能扩展之Ixion标签,实现各种对象在页面上的展示</description> <tlib-version>1.0</tlib-version> <short-name>it</short-name> <uri>http://ixion.net/tag/it</uri> <tag> <name>printer</name> <tag-class>com.kerbores.nutz.tag.ContextPrinter</tag-class> <body-content>empty</body-content> <attribute> <name>value</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> <tag> <name>pager3</name> <tag-class>com.kerbores.nutz.tag.Bootstrap3Pagination</tag-class> <body-content>empty</body-content> <attribute> <name>nameSpace</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>method</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>page</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>maxLength</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>pages</name> <required>true</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>otherParam</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>pageParam</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> <attribute> <name>paramEncoding</name> <required>false</required> <rtexprvalue>true</rtexprvalue> </attribute> </tag> </taglib>
试试其它关键字
bootstrap
分页标签
分页
同语言下
.
List 切割成几份 工具类
.
一行一行读取txt的内容
.
Java PDF转换成图片并输出给前台展示
.
java 多线程框架
.
double类型如果小数点后为零则显示整数否则保留两位小
.
将图片转换为Base64字符串公共类抽取
.
sqlParser 处理SQL(增删改查) 替换schema 用于多租户
.
JAVA 月份中的第几周处理 1-7属于第一周 依次类推 29-
.
java计算两个经纬度之间的距离
.
输入时间参数计算年龄
可能有用的
.
C#实现的html内容截取
.
List 切割成几份 工具类
.
SQL查询 多列合并成一行用逗号隔开
.
一行一行读取txt的内容
.
C#动态修改文件夹名称(FSO实现,不移动文件)
.
c# 移动文件或文件夹
.
c#图片添加水印
.
Java PDF转换成图片并输出给前台展示
.
网站后台修改图片尺寸代码
.
处理大图片在缩略图时的展示
life
贡献的其它代码
(
2
)
.
bootstrap3分页标签
.
读取Excel文档
Copyright © 2004 - 2024 dezai.cn. All Rights Reserved
站长博客
粤ICP备13059550号-3