Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板
个人微信公众号:程序猿的月光宝盒
//当前页
private int pageNum;
//每页的数量
private int pageSize;
//当前页的数量
private int size;
//总页数
private int pages;
//第一页
private int firstPage;
//上一页
private int prePage;
//下一页
private int nextPage;
//总记录数
private long total;
//由于startRow和endRow不常用,这里说个具体的用法
//可以在页面中"显示startRow到endRow 共size条数据"
//当前页面第一个元素在数据库中的行号
private int startRow;
//当前页面最后一个元素在数据库中的行号
private int endRow;
//结果集
private List<T> list;
//是否为第一页
private boolean isFirstPage = false;
//是否为最后一页
private boolean isLastPage = false;
//是否有前一页
private boolean hasPreviousPage = false;
//是否有下一页
private boolean hasNextPage = false;
//导航页码数
private int navigatePages;
//所有导航页号
private int[] navigatepageNums;
//导航条上的第一页
private int navigateFirstPage;
//导航条上的最后一页
private int navigateLastPage;
项目中使用了Mybatis的PageHelper分页插件后的js文件
/**
* 初始化首页数据
*/
function initData(pageNo) {
//清空原来的数据,找到第一个以外的tr,并移除,用 :gt()
$("tr:gt(0)").remove();
$.ajax({
url: "showInvi.do",
type: "post",
dataType: "json",
data: {"pageNo": pageNo},
async: true,
success: function (obj) {
console.log(obj);
if (obj.size === 0) {//如果没有数据
var str = `
<tr>
<td colspan="5">没有符合条件的数据</td>
</tr>
`;
$("#dataTble").append(str);
$("p").html("");
} else {
$.each(obj.list, function (i) {
var str = `
<tr>
<td>${obj.list[i].title}</td>
<td>${obj.list[i].summary}</td>
<td>${obj.list[i].author}</td>
<td>${obj.list[i].createdate}</td>
<td>
<a href="/showReply.html?invid=${obj.list[i].id}">查看回复</a>||<a href="javascript:void(0);" onclick="del(${obj.list[i].id},'${obj.list[i].title}');">删除</a>
</td>
</tr>
`;
$("#dataTble").append(str);
});
$("tr:gt(0):odd").attr("style", "background-color:#90EE90");
//分页,我是放在一个p标签里
var pageFoot = $("p");
//在分页前,清空原来分页的内容
pageFoot.html("");
var pageStr = "";
if (obj.total === 0) {//如果没有数据,就不显示分页条
return;
}
if (obj.isFirstPage && obj.hasNextPage) {//如果是第一页,并且还有下一页
pageStr = `
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;">首 页</a>|
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;"><< 上一页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.nextPage});">下一页>></a>|
<a href="javascript:void(0);" onclick="initData(${obj.pages});">尾 页</a>
`
} else if (obj.isFirstPage && !obj.hasNextPage) {//如果是第一页,并且没有下一页
pageStr = ``//nothing to do
} else if (!obj.isFirstPage && obj.hasNextPage) {//如果不是第一页,并且还有下一页
pageStr = `
<a href="javascript:void(0);" onclick="initData(1)">首 页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.prePage});"><< 上一页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.nextPage});">下一页>></a>|
<a href="javascript:void(0);" onclick="initData(${obj.pages});">尾 页</a>
`
} else if (!obj.isFirstPage && !obj.hasNextPage) {//如果不是第一页,且没有下一页
pageStr = `
<a href="javascript:void(0);" onclick="initData(${obj.firstPage});">首 页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.prePage});"><< 上一页</a>|
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;">下一页>></a>|
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;">尾 页</a>
`
}
pageStr += `
第
${obj.pageNum}
页/共
${obj.pages}
页(${obj.total}条)
`;
pageFoot.append(pageStr);
}
}, error: function () {
alert("initData error");
}
})
}
基本上分页部分可以作为模板
他对应的html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<center>
<h1>帖子列表</h1>
<hr/>
<form id="findInvis">
帖子标题:
<input title="请输入帖子标题" name="title">
<!--input的类型还是submit-->
<input type="submit" value="搜索" >
</form>
<div id="infos">
<br/>
<table border="1" style="width: 100%;text-align: center" id="dataTble">
<tr style="background-color: #6FABC1;">
<td>标题</td>
<td>内容摘要</td>
<td>作者</td>
<td>发布时间</td>
<td>操作</td>
</tr>
</table>
<p></p>
</div>
</center>
<script rel="script" type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script rel="script" type="text/javascript" src="js/list.js"></script>
</body>
</html>
对应的ServiceImpl
@Override
public PageInfo<Map<String, Object>> selectByPrimaryKey(Integer invid,Integer pageNo) {
PageHelper.startPage(pageNo,4);
List<Map<String, Object>> maps = replyDetailMapper.selectByPrimaryKey(invid);
return new PageInfo<> (maps);
}
对应的Controller,是标注@RestController的
@RequestMapping("/showInvi.do")
public PageInfo<Map<String, Object>> selectByTitle(Invitation invitation,Integer pageNo) {
return invitationService.selectByTitle(invitation,pageNo);
}
页面分页模板部分
success : function(obj) {
console.log(obj);
var strData ="";
//在循环的前面清空标题以下的所有行
//获取行>1的那行.调用移除方法
$("tr:gt(1)").remove();
$.each(obj.list,function (i) {
strData +=`
<tr>
<th>${obj.list[i].id}</th>
<th>${obj.list[i].name}</th>
<th>${obj.list[i].age}</th>
<th>${obj.list[i].gender}</th>
<th>${obj.list[i].telephone}</th>
<th>${obj.list[i].email}</th>
<th>${obj.list[i].cname}</th>
<th>
<a href="updates.html?id=${obj.list[i].id}">更新</a>
<a href="javascript:void(0);" onclick="del(${obj.list[i].id})">删除</a>
</th>
</tr>
`;
});
//找到table,并拼接
$("table").append(strData);
//分页
//在分页前,清空原来分页的内容
$("p").html("");
var pageStr = "";
if (obj.total === 0) {//如果没有数据,就不显示分页条
return;
}
if (obj.isFirstPage && obj.hasNextPage) {//如果是第一页,并且还有下一页
pageStr = `
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;">首 页</a>|
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;"><< 上一页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.nextPage});">下一页>></a>|
<a href="javascript:void(0);" onclick="initData(${obj.pages});">尾 页</a>
`
} else if (obj.isFirstPage && !obj.hasNextPage) {//如果是第一页,并且没有下一页
pageStr = ``//nothing to do
} else if (!obj.isFirstPage && obj.hasNextPage) {//如果不是第一页,并且还有下一页
pageStr = `
<a href="javascript:void(0);" onclick="initData(1)">首 页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.prePage});"><< 上一页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.nextPage});">下一页>></a>|
<a href="javascript:void(0);" onclick="initData(${obj.pages});">尾 页</a>
`
} else if (!obj.isFirstPage && !obj.hasNextPage) {//如果不是第一页,且没有下一页
pageStr = `
<a href="javascript:void(0);" onclick="initData(${obj.firstPage});">首 页</a>|
<a href="javascript:void(0);" onclick="initData(${obj.prePage});"><< 上一页</a>|
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;">下一页>></a>|
<a href="javascript:void(0);" style="text-decoration: none;color: grey;cursor:no-drop;">尾 页</a>
`
}
pageStr += `
第
${obj.pageNum}
页/共
${obj.pages}
页(${obj.total}条)
`;
$("p").append(pageStr);
},
Mybatis的PageHelper分页插件的PageInfo的属性参数,成员变量的解释,以及页面模板的更多相关文章
- SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页
SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...
- Springboot 系列(十二)使用 Mybatis 集成 pagehelper 分页插件和 mapper 插件
前言 在 Springboot 系列文章第十一篇里(使用 Mybatis(自动生成插件) 访问数据库),实验了 Springboot 结合 Mybatis 以及 Mybatis-generator 生 ...
- 【spring boot】14.spring boot集成mybatis,注解方式OR映射文件方式AND pagehelper分页插件【Mybatis】pagehelper分页插件分页查询无效解决方法
spring boot集成mybatis,集成使用mybatis拖沓了好久,今天终于可以补起来了. 本篇源码中,同时使用了Spring data JPA 和 Mybatis两种方式. 在使用的过程中一 ...
- Spring Boot整合tk.mybatis及pageHelper分页插件及mybatis逆向工程
Spring Boot整合druid数据源 1)引入依赖 <dependency> <groupId>com.alibaba</groupId> <artif ...
- springboot如何集成mybatis的pagehelper分页插件
mybatis提供了一个非常好用的分页插件,之前集成的时候需要配置mybatis-config.xml的方式,今天我们来看下它是如何集成springboot来更好的服务的. 只能说springboot ...
- 小白的springboot之路(十五)、mybatis的PageHelper分页插件使用
0.前言 用mybatis,那么分页必不可少,基本都是用PageHelper这个分页插件,好用方便: 1.实现 1.1.添加依赖: <!-- 3.集成 mybatis pagehelper--& ...
- 后端——框架——持久层框架——Mybatis——补充——pageHelper(分页)插件
Pagehelper插件的知识点大致可以分为三个部分 搭建环境,引入jar包,配置. 使用方式,只需要记住一种即可.类似于在写SQL语句中,可以left join,也可以right join,它们实现 ...
- Mybatis学习 PageHelper分页插件
1.Maven依赖,注意使用PageHelper时的版本必须与Mybatis版本对应 1 <!-- 添加Mybatis依赖 --> 2 <dependency> 3 <g ...
- Mybatis第三方PageHelper分页插件原理
欢迎关注公号:BiggerBoy,看更多文章 原文链接:https://mp.weixin.qq.com/s?__biz=MzUxNTQyOTIxNA==&mid=2247485158&a ...
随机推荐
- 基于JDK1.8的JVM 内存结构【JVM篇三】
目录 1.内存结构还是运行时数据区? 2.运行时数据区 3.线程共享:Java堆.方法区 4.线程私有:程序计数器.Java 虚拟机栈.本地方法栈 5.JVM 内存结构总结 在我的上一篇文章别翻了,这 ...
- python数据挖掘第二篇-爬虫
python爬虫 urllib用法 eg1: from urllib import request data = request.urlopen(urlString).read() # data获取的 ...
- PlantUML Viewer Chrome 插件 画时序图
PlantUML通过简单直观的语言来定义示意图 使用 Chrome+ PlantUML Viewer的插件画图 1,打开chrome网上应用店 2,搜索plantuml viewer 并添加 3,扩展 ...
- ARTS-S c语言统计程序运行时间
#include <stdio.h> #include <sys/time.h> #include <unistd.h> int main() { struct t ...
- 用HAL库结合STM cube编写代码控制stm32f103c8t6来驱动减速电机实现慢快逐步切换转动
用到的模块 TB6612FNG电机驱动模块 stm32F103C8T6最小系统板 LM2596S降压模块 直流减速电机(不涉及编码器知识) 模块介绍 1.TB6612FNG电机驱动模块 (1)< ...
- Mybatis需要注意的细节
mybatis第二篇 1.${}和#{}的区别 1.#在传参的时候,会自动拼接单引号:$不能拼接单引号; 2.$传参时,一般不支持jdbcType指定类型的写法;#则可以;如: #{name,jd ...
- NIO Buffer 内部机理使用姿势
关于NIO Buffer中4个重要状态属性 position.limit.capacity 与 mark Buffer本身是一个容器,称作缓冲区,里面包装了特定的一种原生类型,其子类包括ByteBuf ...
- c++ const问题小记
int* a = new int; const int* b = a; const int* a = new int; int* b = (int*)a; const int m = 10; int ...
- intellij cpu占有高解决办法(亲测有效!)
File---Settings---Inspections---把勾都去掉或者选自己需要的部分.
- Ubuntu虚拟机安装VMware Tools
前言 在用VMware安装好Linux虚拟机后,发现在虚拟机下安装的Ubuntu16.04 64位无法进入全屏模式,同时存在物理机和虚拟机之间无法实现文件传输的问题,通过安装VMware Tools得 ...