原文链接:http://www.hxstrive.com/article/178.htm
在日常进行开发中,当数据量太多时,为了提高效率,我们会采用分页的方式展示数据。这样每次检索数据到展示出来的时间将大大缩小。在使用Freemarker的时候我了方便,写了一个简单的分页插件。该插件支持三种皮肤。
Freemarker插件内容如下(pageShow.ftl):
<#-- 分页控件-->
<#-- 分页组件的使用 -->
<#--
pageShow 总页数, 当前页, 请求服务地址, 页面大小默认15, 显示最多分页个数, 请求服务地址参数默认为p, 分页样式(可选:gray(默认)、orange、blue)
<#import "pub/pageShow.ftl" as page>
<@page.pageShow pageCount, curPage, "pagePluginTest.do", pageSize, "blue"/>
-->
<#macro pageShow _totalPageNum _currentPageNo _pageName _pageSize=15 _styleClassName="gray" _maxShowNums=10 _defaultPageParameter="p" >
<#-- 本段默认起始页 -->
<#local _pageStartNo = 1/>
<#-- 本段默认结束页 -->
<#local _pageEndNo = _maxShowNums />
<#-- 分页的第一页 -->
<#local _firstPageNo = 1 />
<#-- 分页的最后一页 -->
<#local _lastPageNo = _totalPageNum>
<#-- 前一页号码 -->
<#local _prePageNo = _currentPageNo-1 />
<#-- 后一页号码 -->
<#local _nextPageNo = _currentPageNo+1 />
<#if _currentPageNo == _pageStartNo>
<#local _prePageNo = _pageStartNo />
</#if>
<#if _currentPageNo == _lastPageNo>
<#local _nextPageNo = _lastPageNo />
</#if>
<#if _currentPageNo gt _maxShowNums>
<#local _thisPageSegment = ((_currentPageNo-1) / _maxShowNums)?int + 1/>
<#assign _thisPageStartNo = _pageStartNo + (_thisPageSegment-1) * _maxShowNums/>
<#assign _thisPageEndNo = _pageEndNo + (_thisPageSegment-1) * _maxShowNums/>
<#if _thisPageEndNo gt _totalPageNum>
<#assign _thisPageEndNo = _totalPageNum>
</#if>
<#else>
<#assign _thisPageStartNo = _pageStartNo />
<#assign _thisPageEndNo = _pageEndNo />
</#if>
<#-- 构造当前分页栏上面的分页按钮 -->
<#local _pages=[] />
<#if _totalPageNum != 0>
<#list _thisPageStartNo .. _thisPageEndNo as _index>
<#if _currentPageNo == _index >
<#local _pages = _pages + [{"pageNum" : _index ,"url" : _pageName+"?"+_defaultPageParameter+"="+_index , "current" : true}] />
<#else>
<#local _pages = _pages + [{"pageNum" : _index ,"url" : _pageName+"?"+_defaultPageParameter+"="+_index , "current" : false}] />
</#if>
</#list>
</#if>
<#-- 构造分页栏HTML代码 -->
<#local _htmlNoLinkLine>
<a href = "${_pageName}?${_defaultPageParameter}=${_firstPageNo}" target = "_self">首页</a>
<#if _currentPageNo != _pageStartNo>
<a href = "${_pageName}?${_defaultPageParameter}=${_prePageNo}" target = "_self">上一页</a>
</#if>
<#list _pages as page>
<#if page.current?default(false)>
<span class="current" >${page.pageNum}</span>
<#else>
<a href="${page.url}" mce_href="${page.url}" target="_self">${page.pageNum}</a>
</#if>
</#list>
<#if _currentPageNo != _lastPageNo>
<a href = "${_pageName}?${_defaultPageParameter}=${_nextPageNo}" target = "_self">下一页</a>
</#if>
<a href = "${_pageName}?${_defaultPageParameter}=${_lastPageNo}" target = "_self">末页</a>
<span>共${_totalPageNum?default(0)}页</span>
</#local>
<!-- 将分页HTML代码放置到页面 -->
<div class="${_styleClassName}">
${_htmlNoLinkLine}
</div>
<!-- 分页插件CSS -->
<style type="text/css" mce_bogus="1">
<#if _styleClassName == "gray">
<#-- CSS gray style pagination -->
div.gray {
font-size: 12px;
font-family: verdana, arial, helvetica, sans-serif;
padding: 3px;
margin: 3px;
text-align: center;
color:#999999;
}
div.gray a {
border: #E1E2E3 1px solid;
padding: 7px 14px;
margin: 2px;
color: #0000CC;
text-decoration: none;
}
div.gray a:hover {
border: #3388FF 1px solid;
background: #F2F8FF;
}
div.gray a:active {
color: #FF0000;
}
div.gray span.current {
border: transparent 1px solid;
font-weight: bold;
margin: 2px;
padding: 7px 14px;
color: #333333;
}
</#if>
<#if _styleClassName == "orange">
<#-- CSS orange style pagination -->
div.orange {
font-size: 12px;
font-family: verdana, arial, helvetica, sans-serif;
padding: 3px;
margin: 3px;
text-align: center;
color:#999999;
}
div.orange a {
border: #DFDFDF 1px solid;
padding: 7px 14px;
margin: 2px;
color: #3D3D3D;
text-decoration: none;
}
div.orange a:hover {
border: #FE4500 1px solid;
background: transparent;
color:#FE4500;
}
div.orange a:active {
color: #FE4500;
}
div.orange span.current {
border: #FF4400 1px solid;
background: #FF4400;
font-weight: bold;
margin: 2px;
padding: 7px 14px;
color: #FFFFFF;
}
</#if>
<#if _styleClassName == "blue">
<#-- CSS blue style pagination -->
div.blue {
font-size: 12px;
font-family: verdana, arial, helvetica, sans-serif;
padding: 3px;
margin: 3px;
text-align: center;
color:#999999;
}
div.blue a {
border: #E1E2E3 1px solid;
padding: 7px 14px;
margin: 2px;
color: #808080;
text-decoration: none;
}
div.blue a:hover {
border: #389CFF 1px solid;
background: transparent;
color:#389CFF;
}
div.blue a:active {
color: #389CFF;
}
div.blue span.current {
border: #389CFF 1px solid;
background: #389CFF;
font-weight: bold;
margin: 2px;
padding: 7px 14px;
color: #FFFFFF;
}
</#if>
</style>
</#macro>
分页插件的使用:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Freemarker分页</title>
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="this is my page">
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
</head>
<body>
<table width="100%" border="1" cellpadding="0" cellspacing="0" style="text-align:center;">
<tr style="background:#808080;text-align:center;height:30px;">
<td>ID</td>
<td>姓名</td>
<td>性别</td>
<td>年龄</td>
</tr>
<#list userList as user>
<tr height="30px">
<td>
<#if user.id?exists> ${user.id} </#if>
</td>
<td>
<#if user.name?exists> ${user.name} </#if>
</td>
<td>
<#if user.sex?exists> ${user.sex} </#if>
</td>
<td>
<#if user.age?exists> ${user.age} </#if>
</td>
</tr>
</#list>
<tr height="160px">
<td colspan="4" align="center">
<!--
pageShow 总页数, 当前页, 请求服务地址, 页面大小默认15, 显示最多分页个数, 请求服务地址参数默认为p, 分页样式(可选:gray(默认)、orange、blue)
-->
<#import "pub/pageShow.ftl" as page>
<@page.pageShow pageCount, curPage, "pagePluginTest.do", pageSize, "gray"/><br/>
<@page.pageShow pageCount, curPage, "pagePluginTest.do", pageSize, "blue"/><br/>
<@page.pageShow pageCount, curPage, "pagePluginTest.do", pageSize, "orange"/>
</td>
</tr>
</table>
</body>
</html>
效果图:
相关推荐
多数据源部分代码,直接运行beta\src\main\java\org\springframework\jdbc\datasource\lookup下Test的main方法,可根据业务开放接口
ssm整合freemarker---Demo 还有pagehelper 分页插件
如果切换至sqlite数据库时,则application.properties当中的mybatis分页插件需要改成支持sqlite; 示例启动 启动工程; 运行cn.springboot.Application当中的main方法; 浏览器访问, 测试账号是admin/123456,即可看...
pagehelper分页插件 前端 Bootstrap jQuery Vue.js Datatables 安装教程 本地准备开发工具IDE,建议使用eclipse 或者springSTS 安装JDK1.8,并配置环境变量 安装maven,并配置本地仓库 安装mysql5.X并配置
actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过AOP记录web请求日志)、统一异常处理(json级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、Beetl(模板引擎)、Enjoy(模板引擎)、...
actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过AOP记录web请求日志)、统一异常处理(json级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、Beetl(模板引擎)、Enjoy(模板引擎)、...
PageHelper-Mybatis通用分页插件 FreeMarker-模板引擎 前端 Bootstrap jQuery jQuery Form Vue.js pace.js–网页自动加载进度条插件 bootstrapValidator.js-最好用的bootstrap表单验证插件 lobibox-强大的jQuery消息...
actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过AOP记录web请求日志)、统一异常处理(json级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、Beetl(模板引擎)、Enjoy(模板引擎)、...
模板引擎)、JdbcTemplate( 通用JDBC操作数据库)、JPA( 强大的ORM框架) 、mybatis( 强大的ORM框架)、通用Mapper( 快速操作Mybatis)、PageHelper( 通用的Mybatis分页插件)、mybatis-plus( 快速操作Mybatis)、BeetlSQL...
pringboot后台OA办公管理系统 项目描述 Maven进行项目管理,基于springboot框架开发的项目,mysql底层数据库,前端采用freemarker模板引擎,...pagehelper Mybatis分页插件 1.0.0 https://pagehelper.github.io
集成MyBatis、PageHelper分页插件 提供代码生成器根据表名生成对应的Domain(领域对象)、Mapper、MapperXML、Service、Controller等基础代码 没有集成mybatis generator,全部使用freemarker模板生成,模板随便改 ...
actuator(监控)、admin(可视化监控)、logback(日志)、aopLog(通过AOP记录web请求日志)、统一异常处理(json级别和页面级别)、freemarker(模板引擎)、thymeleaf(模板引擎)、Beetl(模板引擎)、Enjoy(模板引擎)、...
项目技术(必填)技术名称版本官方网SpringBoot SpringBoot框架1.5.6.RELEASE JPA spring-data-jpa 1.5.6.RELEASE Mybatis Mybatis框架1.3.0 fastjson json解析包1.2.36 pagehelper Mybatis分页插件1.0。 0 数据库...
这套项目用到很多潮流技术,包括SpringBoot、lombok、MyBatis、分页助手、freemarker、SpringMVC、SpringMail、百度地图技术等等 技术栈 SpringBoot + SpringMVC + Spring + MyBatis + 百度地图 运行环境 IDEA + ...
商品编辑:商品增删改查,使用了分页插件 上架:更改商品状态,添加商品信息到solr服务器,静态化商品页面 系统前台 商品检索:使用solr服务器进行全文检索,商品详情页面采用freemarker实现静态化 购物车:采用...
自己写项目写出来的SSM框架模板,纯原创。 需要可以自行购买,保证不亏。...3. MyBatis分页pagehelper、MyBatis缓存 4. jstl、jsp、Servlet、log4j、freemarker 5. shiro、lombok插件、文件上传 ......等等
java开发oa办公系统源码 oasys(OA自动化办公系统) 1.项目介绍 oasys是一个OA办公自动化系统,使用Maven进行项目管理,基于springboot框架开发的项目,mysql底层数据库,前端采用freemarker模板...Mybatis分页插件 1.0.0
java开发oa办公系统源码 1. 项目介绍 本项目是一个OA办公自动化系统,使用Maven进行项目管理,基于Springboot框架开发的项目,MySQL底层数据库,前端采用...Mybatis分页插件 1.0.0 3. 部署流程 1.下载项目、把
Enjoy(模板引擎),JdbcTemplate(通用JDBC操作数据库),JPA(强大的ORM框架),强大的ORM框架(强大的ORM框架),通用Mapper(快速操作Mybatis Mybatis),PageHelper(通用的Mybatis分页插件),mybatis-plus...
socket工具类,权限组件,菜单组件,jdbc分页支持多种数据库,ant路径工具类,增加jquery easyUI 1.0.9 版本管理,服务根路径工具类,文件上传工具类 1.0.10 集成ueditor在线编辑器 1.0.11 地址联动 1.0.12 Excel工具类 ...