package com.fendo.util;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.lang3.StringUtils;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
public class PageUtils {
/**
* 封装分页数据到Map中。
*/
public static Map<String, Object> getPageMap(Page<?> objPage) {
Map<String, Object> resultMap = new HashMap<String, Object>();
resultMap.put("resultList", objPage.getContent()); // 数据集合
resultMap.put("totalNum", objPage.getTotalElements()); // 总记录数
resultMap.put("totalPage", objPage.getTotalPages()); // 总页数
resultMap.put("pageNum", objPage.getNumber()); // 当前页码
resultMap.put("pageSize", objPage.getSize()); // 每页显示数量
return resultMap;
}
/**
* 创建分页请求。
*
* @param pageNum 当前页
* @param pageSize 每页条数
* @param sortType 排序字段
* @param direction 排序方向
*/
public static PageRequest buildPageRequest(int pageNum, int pageSize, String sortType, String direction) {
Sort sort = null;
if (!StringUtils.isNotBlank(sortType)) {
return new PageRequest(pageNum - 1, pageSize);
} else if (StringUtils.isNotBlank(direction)) {
if (Direction.ASC.equals(direction)) {
sort = new Sort(Direction.ASC, sortType);
} else {
sort = new Sort(Direction.DESC, sortType);
}
return new PageRequest(pageNum - 1, pageSize, sort);
} else {
sort = new Sort(Direction.ASC, sortType);
return new PageRequest(pageNum - 1, pageSize, sort);
}
}
/**
* 创建分页请求(该方法可以放到util类中).
*/
public static PageRequest buildPageRequest(int pageNum, int pageSize, String sortType) {
return buildPageRequest(pageNum, pageSize, sortType, null);
}
/**
* 创建分页请求
*
* @author YangZhenghua
* @date 2014-11-12
*
* @param pageNum
* @param pageSize
* @param sort
* @return
*/
public static PageRequest buildPageRequest(int pageNum, int pageSize, Sort sort) {
return new PageRequest(pageNum - 1, pageSize, sort);
}
/**
* 创建分页请求(该方法可以放到util类中).
*/
public static PageRequest buildPageRequest(int pageNum, int pageSize) {
return buildPageRequest(pageNum, pageSize, null, null);
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
Spring Data JPA+kkpager分页DEMO
共55个文件
xml:8个
class:8个
java:7个
3星 · 超过75%的资源 需积分: 10 37 下载量 97 浏览量
2017-06-11
17:25:47
上传
评论
收藏 251KB ZIP 举报
温馨提示
Spring Data JPA+kkpager实现的一个简单分页DEMO
资源推荐
资源详情
资源评论
收起资源包目录
Spring Data JPA+kkpager分页DEMO.zip (55个子文件)
JPA
.project 1KB
.springBeans 533B
src
test
java
main
webapp
WEB-INF
web.xml 4KB
index.jsp 571B
success.jsp 807B
datatable.jsp 5KB
js
jquery.min.js 95KB
kkpager.min.js 6KB
bootstrap.min.js 36KB
jquery-1.10.2.min.js 91KB
font
glyphicons-halflings-regular.ttf 44KB
glyphicons-halflings-regular.woff2 18KB
glyphicons-halflings-regular.eot 20KB
glyphicons-halflings-regular.svg 106KB
glyphicons-halflings-regular.woff 23KB
css
kkpager_orange.css 2KB
bootstrap.min.css 118KB
bootstrap-theme.min.css 23KB
kkpager_blue.css 2KB
resources
config.properties 504B
applicationContext.xml 5KB
spring-mvc.xml 3KB
java
com
fendo
service
imp
FamilyServiceImp.java 3KB
FamilyService.java 425B
controller
DataTableController.java 1KB
dao
FamilyDao.java 397B
util
FamilyUtil.java 1KB
PageUtils.java 3KB
entity
FamilyMember.java 2KB
target
m2e-wtp
web-resources
META-INF
MANIFEST.MF 107B
maven
com.fendo
JPA
pom.properties 199B
pom.xml 9KB
classes
config.properties 504B
applicationContext.xml 5KB
com
fendo
service
FamilyService.class 603B
imp
FamilyServiceImp$1.class 3KB
FamilyServiceImp.class 3KB
controller
DataTableController.class 2KB
dao
FamilyDao.class 510B
util
PageUtils.class 3KB
FamilyUtil.class 1KB
entity
FamilyMember.class 3KB
spring-mvc.xml 3KB
test-classes
.settings
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.common.project.facet.core.xml 252B
org.eclipse.m2e.core.prefs 90B
org.eclipse.ltk.core.refactoring.prefs 106B
org.eclipse.jdt.core.prefs 736B
org.eclipse.wst.validation.prefs 50B
org.eclipse.wst.jsdt.ui.superType.name 6B
org.eclipse.core.resources.prefs 138B
org.eclipse.wst.common.component 650B
.jsdtscope 639B
pom.xml 9KB
.classpath 1KB
共 55 条
- 1
资源评论
- andy111111112018-10-09还可以,感谢分享
- 风沙沙2018-02-08...... .... .. .. . .....参考一下
码农致富
- 粉丝: 3669
- 资源: 112
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功