Spring Data JPA + layui的前台分页插件layPage实现页面的分页
一、后台代码:
1.1 controller层代码
@RequestMapping("/xxxxxx")
public String showInformationCode(String pageNum ,Model model,HttpServletRequest request){
String id = (String)request.getSession().getAttribute("Id");
if(pageNum == null){
pageNum="1";
}
int parseInt = Integer.parseInt(pageNum);
if (StringUtils.isBlank(id)) {
return null;
}
Page<Test> selectTestListById = informationService.selectTestListById(id ,parseInt);//jpa的分页查询,parseInt(第几页)
model.addAttribute("selectTestListById ",selectTestListById );
return "test";
}
1.2 service层代码
public static final int PAGE_SIZE = 10; //全局变量PAGE_SIZE(每页显示的数据条数) /**
* 分页查询
* @param csdbId
* @param pageable
* @return
*/
public Page<Test> selectTestListByCsdbId(String id ,int pageNumber) {
PageRequest buildPageRequest = BuildPageRequest(pageNumber, PAGE_SIZE);
Page<Test> findById = testMapper.findById(id, buildPageRequest);
return findById ;
} public static PageRequest buildPageRequest(int pageNumber, int pagzSize){
return new PageRequest(pageNumber - 1, pagzSize, null);
}
1.3 mapper层代码
public interface CsdbSetDmInformationCodeMapper extends JpaRepository<CsdbSetDmInformationCode, String>{
/**
* 分页
*/
Page<Test> findById(String id ,Pageable pageable);
//批量删除
@Transactional
@Modifying
@Query(value="delete from tablre where id in ?1 ",nativeQuery=true)
int deleteByPrimaryKeys(List<String> ids);
}
这样传入前台的数据就只有10条,直到下一次请求的到来,在根据传入的pageNum(页数)来确定传入前台的数据(eg:每页的条数我是通过全局变量写死了的,可以自行修改)
二、前台使用layui的layPage插件来实现分页
2.1 首先要在页面上引入layui的js和css(也可直接引用layPage.js),layui的下载地址:http://res.layui.com/download/layui/layui-v2.0.2.zip
2.2 前台test.html页面
<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-4.dtd">
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"
xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>information code</title>
<link rel="stylesheet" th:href="@{/libs/plugin/layui/css/layui.css}">
<link rel="stylesheet" th:href="@{/css/test.css}">
</head>
<body>
<div id="warpper">
<div id="informationCode">
<table class="bordered">
<thead>
<tr>
<th>
<input type="checkbox" class="check-all">
</th>
<th>Information Code</th>
<th>InfoName</th>
<th>Front Matter Routine</th>
</tr>
</thead>
<tbody>
<tr th:each = "informationCode : ${selectTestListById.content}" th:id="${informationCode.id}">
<td><input type="checkbox" th:value="${informationCode.id}" name="idCheckbox"></td>
<td class="informationcode"><input type="text" class="input-style" th:value="${informationCode.informationcode}" readonly="readonly"/></td>
<td class="infoname"><input type="text" class="input-style" th:value="${informationCode.infoname}"/></td>
</tr>
</tbody>
</table> <div id="pages">
</div>
<input type="hidden" th:value="${informationCodeList.TotalPages}" id="pageTotal"> <!-- 总条数 -->
<input type="hidden" th:value="${informationCodeList.number+1}" id="page"> <!-- 第几页 -->
</div>
<div id="btnBox">
<input type="button" value="New" class="btn-style fl" id="informationCodeAdd">
<input type="button" value="Delete" class="btn-style fl" id="informationCodeDel">
<a class="btn-href" href="/csdb/info/informationCodeDefault.shtml">
<input type="button" value="Default" class="btn-style fl" id="informationCodeDefault"/></a>
<input type="button" value="Save" class="btn-style fl" id="informationCodeSave">
</div>
</div>
</body>
<script th:src="@{/csdb/libs/jquery/jquery-3.2.1.js}" type="text/javascript"></script>
<script th:src="@{/csdb/libs/plugin/layui/layui.js}" type="text/javascript"></script> <script>
<!-- /**
* 分页(layui的版本为1.0.9时使用)
*/
layui.use('laypage', function(){
var laypage = layui.laypage; //执行一个laypage实例
laypage({
cont: 'pages',
pages: $("#pageTotal").val(),
skip: true, //控制分页皮肤
curr:$("#page").val(),
jump:function (obj,first){
if(!first){
window.location.href="/csdb/info/informationCode.shtml?pageNum="+obj.curr
}
}
});
}); --> /**
* 分页(layui的版本为2.x时使用)
*/
layui.use('laypage', function(){
var laypage = layui.laypage; //执行一个laypage实例
laypage({
elem: 'pages', //不同于1.0.9版本
count: $("#pageTotal").val(), //切换分页的回调,当分页被切换时触发,函数返回两个参数:obj(当前分
//页的所有选项值)、first(是否首次,一般用于初始加载的判断)
jump:function (obj,first){
if(!first){
window.location.href="/xxxxxx?pageNum="+obj.curr
}
}
});
}); </script>
</html>
Spring Data JPA + layui的前台分页插件layPage实现页面的分页的更多相关文章
- 整合Spring Data JPA与Spring MVC: 分页和排序
之前我们学习了如何使用Jpa访问关系型数据库.比较完整Spring MVC和JPA教程请见Spring Data JPA实战入门,Spring MVC实战入门. 通过Jpa大大简化了我们对数据库的开发 ...
- 整合Spring Data JPA与Spring MVC: 分页和排序pageable
https://www.tianmaying.com/tutorial/spring-jpa-page-sort Spring Data Jpa对于分页以及排序的查询也有着完美的支持,接下来,我们来学 ...
- 快速搭建springmvc+spring data jpa工程
一.前言 这里简单讲述一下如何快速使用springmvc和spring data jpa搭建后台开发工程,并提供了一个简单的demo作为参考. 二.创建maven工程 http://www.cnblo ...
- Spring Data JPA进阶——Specifications和Querydsl
Spring Data JPA进阶--Specifications和Querydsl 本篇介绍一下spring Data JPA中能为数据访问程序的开发带来更多便利的特性,我们知道,Spring Da ...
- 如何在Spring Data JPA中引入Querydsl
一.环境说明 基础框架采用Spring Boot.Spring Data JPA.Hibernate.在动态查询中,有一种方式是采用Querydsl的方式. 二.具体配置 1.在pom.xml中,引入 ...
- Spring Boot 应用系列 1 -- Spring Boot 2 整合Spring Data JPA和Druid,双数据源
最近Team开始尝试使用Spring Boot + Spring Data JPA作为数据层的解决方案,在网上逛了几圈之后发现大家并不待见JPA,理由是(1)MyBatis简单直观够用,(2)以Hib ...
- Hibernate、Mybatis与Spring Data JPA
从零开始集成Springboot+MyBatis+JPA https://www.jianshu.com/p/e14c4a6f6871 MyBatis 与Hibernate的区别 http://xhr ...
- 使用Spring Data JPA进行数据分页与排序
一.导读 如果一次性加载成千上万的列表数据,在网页上显示将十分的耗时,用户体验不好.所以处理较大数据查询结果展现的时候,分页查询是必不可少的.分页查询必然伴随着一定的排序规则,否则分页数据的状态很难控 ...
- javaweb各种框架组合案例(四):maven+spring+springMVC+spring data jpa(hibernate)【失败案例】
一.失败案例 1. 控制台报错信息 严重: Exception sending context initialized event to listener instance of class org. ...
随机推荐
- new与malloc的区别,以及内存分配浅析
从函数声明上可以看出.malloc 和 new 至少有两个不同: new 返回指定类型的指针,并且可以自动计算所需要大小.比如: 1 2 3 int *p; p = new int; //返回类型 ...
- 微信web端生成支付二维码
授权获取二维码类: <?php /** * Trade类 * @author xyyphp * @date 2016/10/10 */ abstract class TradeControlle ...
- JSch基本使用
JSch基本使用 JSch 是SSH2的一个纯Java实现.它允许你连接到一个sshd 服务器,使用端口转发,X11转发,文件传输等等.你可以将它的功能集成到你自己的 程序中.同时该项目也提供一个J2 ...
- thinkphp 3.2.3 计划任务具体实现实例教程
thinkphp 3.2.3 计划任务具体实现实例教程 很多情况下,我们网站都会用到计划任务即定时更新做一些处理,类似Discuz后台的计划任务,比如更新每日发帖数目等等! 这里TP也是可以实现的,首 ...
- JVM内存管理和问题简要分析学习
Java中我们基本上不会显式地调用分配内存的函数,分配内存和回收内存都由JVM自动完成了. 所谓物理内存就是我们通常说的RAM(随机存储器),计算机中还有一个存储单元叫做寄存器,用于存储计算单 ...
- PyQt 5菜单和工具栏
QMainWindow类提供主要应用程序的窗口,有添加状态栏.工具栏.菜单栏等功能 状态栏 self.statusBar().showMessage('Ready') # 创建一个状态栏 # 状态栏显 ...
- 大白话系列之C#委托与事件讲解大结局
声明:本系列非原创,因为太精彩才转载,如有侵权请通知删除,原文:http://www.cnblogs.com/wudiwushen/archive/2010/04/20/1698795.html 今天 ...
- css/css3实现未知宽高元素的垂直居中和水平居中
题目:.a{ width: 200px; height: 200px; background-color: #ccc;} <body> <div class="a" ...
- Cisco动态路由 OSPF协议
OSPF描述: 组播扩展OSPF 锁定 同义词 ospf一般指组播扩展OSPF 本词条由“科普中国”百科科学词条编写与应用工作项目 审核 . OSPF(Open Shortest Path Firs ...
- 【转】Android编码规范建议18条
转自:http://www.chinaz.com/design/2015/0908/443732.shtml Android编码规范建议18条 适合手机app设计师和android 工程师阅读. 1. ...