<!-- 加入 pagehelper 分页插件  jar包-->
<dependency>
<groupId>com.github.pagehelper</groupId>
<artifactId>pagehelper-spring-boot-starter</artifactId>
<version>1.2.5</version>
</dependency> 在 application.properties 加上
#开启分页
# 指定数据库
pagehelper.helperDialect=mysql
# 需要启用 不然会报空数据的
pagehelper.reasonable=true
# 默认值false,分页插件会从查询方法的参数值中
pagehelper.supportMethodsArguments=true
# 用于从对象中根据属性名取值
pagehelper.params=count=countSql 接收 前端传过来的 页码 和 条数

java 后台 代码如下:

@RequestMapping("admin/queryAdminInfoAll")
public ResultFormatPaging queryAdminInfoAll(@RequestParam("page") Integer page, @RequestParam("limit") Integer limit) {
/**
* 加入 页码 条数 需要写在 adminEntityList 数据的前面
*/
PageHelper.startPage(page, limit);
List<AdminEntity> adminEntityList = adminService.queryAdminInfoAll(map); logger.info("admin控制器打印 adminEntityList = {}", adminEntityList); /**
* 加入数据 自动分页
*/
PageInfo pageInfo = new PageInfo(adminEntityList); /**
* 总条数
*/
Integer count = Math.toIntExact(pageInfo.getTotal()); /**
* 返回数据
* code 为 0
* count 数据的总条数
* pageInfo.getList() 分页 之后的格式
*/
return ResultPagingUtil.pagingSuccess(0, count, pageInfo.getList());
}
# 前端 layui 分页 浏览器打印的数据结构 由于 是数据包含着数据 我采用layui 提供的 templet 模板
 {
field: 'adminInfoEntity', title: '手机号码', sort: true,
templet: function (data) {
return '<span>' + data.adminInfoEntity.adminInfoPhone + '</span>'
}
}
layui js 代码:

table.render({
elem: '#adminInfoList'
, url: '/admin/queryAdminInfoAll'
, cols: [[
{type: 'checkbox', fixed: 'left'},
{
field: 'adminInfoEntity', title: '头像',
templet: function (data) {
return '<img class="layui-circle adminImage" width="26" height="26" src=../../' + data.adminInfoEntity.adminInfoImage + '>'
}
}
, {field: 'adminAccount', title: '登录名'}
, {
field: 'adminInfoEntity', title: '邮箱', sort: true,
templet: function (data) {
return '<span>' + data.adminInfoEntity.adminInfoEmail + '</span>'
}
}
, {
field: 'adminInfoEntity', title: '权限',
templet: function (data) {
if (data.adminInfoEntity.adminInfoClass == 0) {
return '<span>' + "普通管理员" + '</span>'
}
if (data.adminInfoEntity.adminInfoClass == 1) {
return '<span>' + "超级管理员" + '</span>'
} }
}
, {
field: 'adminInfoName', title: '实名',
templet: function (data) {
return '<span>' + data.adminInfoEntity.adminInfoName + '</span>'
}
}
, {
field: 'adminInfoEntity', title: '状态', width: 85, templet: function (data) {
if (data.adminInfoEntity.adminInfoCode == 1) { return '<div> <input type="checkbox" checked="" name="codeSwitch" lay-skin="switch" id="open" lay-filter="switchTest" switchId=' + data.adminInfoEntity.adminInfoId + '' +
' lay-text="启用|禁用" value=' + data.adminInfoEntity.adminInfoCode + '></div>'
} else {
return '<div> <input type="checkbox" lay-skin="switch" name="codeSwitch" switchId=' + data.adminInfoEntity.adminInfoId + ' lay-filter="switchTest"' +
'lay-text="启用|禁用" value=' + data.adminInfoEntity.adminInfoCode + '></div>'
}
}
}
, {
field: 'adminInfoEntity', title: '性别',
templet: function (data) {
if (data.adminInfoEntity.adminInfoSex == 2) {
return '<span>' + '男' + '</span>'
}
if (data.adminInfoEntity.adminInfoSex == 0) {
return '<span>' + '保密' + '</span>'
}
if (data.adminInfoEntity.adminInfoSex == 1) {
return '<span>' + '女' + '</span>'
} }
}
, {
field: 'adminInfoEntity', title: '手机号码', sort: true,
templet: function (data) {
return '<span>' + data.adminInfoEntity.adminInfoPhone + '</span>'
}
}
, {fixed: 'right', title: '操作', toolbar: '#barDemo', width: 140}
]]
, limit: 15
, limits: [15, 20, 25, 50, 100]
, parseData: function (data) {
/**
* 打印数据
*
*/
console.log(data)
}
/**
* 开启分页
*/
, page: true
});

html 代码:

<table class="layui-hide" id="adminInfoList"></table>

<script type="text/html" id="barDemo">
<a class="layui-btn layui-btn-xs" lay-event="edit" title="修改管理员信息"> <i class="layui-icon"></i></a>
<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del" title="删除管理员"> <i class="layui-icon"></i></a>
<a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="queryLog" title="查看管理员日志"> <i class="layui-icon"></i></a>
</script>
如问题请留言 感谢观看

springBoot mybatis mysql pagehelper layui 分页的更多相关文章

  1. 7、SpringBoot+Mybatis整合------PageHelper简单分页

    开发工具:STS 代码下载链接:https://github.com/theIndoorTrain/SpringBoot_Mybatis/tree/1d30d2a573ce6784149a28af9b ...

  2. SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页

    SpringBoot+Mybatis配置Pagehelper分页插件实现自动分页 **SpringBoot+Mybatis使用Pagehelper分页插件自动分页,非常好用,不用在自己去计算和组装了. ...

  3. Springboot+Mybatis+MySQL实例练习时踩坑记录

    最近刚开始学习后端,直接让上手学习Springboot+Mybatis+MySQL对CRUD的实例,虽然实例不难,但是上面的三个知识我都不懂,就有点为难我了 所以经常遇到一个点卡自己很久的情况,这里列 ...

  4. springboot成神之——springboot+mybatis+mysql搭建项目简明demo

    springboot+mybatis+mysql搭建项目简明demo 项目所需目录结构 pom.xml文件配置 application.properties文件配置 MyApplication.jav ...

  5. 【SpringBoot】SpringBoot/MyBatis/MySql/thymeleaf/Log4j整合工程

    工程下载地址:https://files.cnblogs.com/files/xiandedanteng/MMSpringWeb20191027-1.rar 工程目录结构如图: 1.创建工程 有些网文 ...

  6. SpringBoot+MyBatis+Mysql 6.X 版本日期型数据获,时间错乱,jason序列化时间相差8小时问题

    新项目是用的springboot+mybatis+mysql 6.0.6版本的驱动包来搭建的,在使用的过程中遇到以下2个问题 从mysql取的的数据日期时间,与真实的时间往后错乱了14个小时. spr ...

  7. SpringBoot+Mybatis+MySql 自动生成代码 自动分页

    一.配置文件 <!-- 通用mapper --> <dependency> <groupId>tk.mybatis</groupId> <arti ...

  8. 从 0 使用 SpringBoot MyBatis MySQL Redis Elasticsearch打造企业级 RESTful API 项目实战

    大家好!这是一门付费视频课程.新课优惠价 699 元,折合每小时 9 元左右,需要朋友的联系爱学啊客服 QQ:3469271680:我们每课程是明码标价的,因为如果售价为现在的 2 倍,然后打 5 折 ...

  9. SpringBoot+MyBatis+MySQL读写分离(实例)

    ​ 1. 引言 读写分离要做的事情就是对于一条SQL该选择哪个数据库去执行,至于谁来做选择数据库这件事儿,无非两个,要么中间件帮我们做,要么程序自己做.因此,一般来讲,读写分离有两种实现方式.第一种是 ...

随机推荐

  1. SSM框架三分钟搞定分页查询

    使用的国产第三方jar   pagehelper 里面的基本属性值 //当前页 private int pageNum; //每页的数量 private int pageSize; //当前页的数量 ...

  2. 吴裕雄--天生自然 PYTHON数据分析:基于Keras的CNN分析太空深处寻找系外行星数据

    #We import libraries for linear algebra, graphs, and evaluation of results import numpy as np import ...

  3. Python之路购物车

    #coding:utf-8 wages=raw_input('what are your wages:') lise_commodity=[('apples',50),('orange',55),(' ...

  4. loadrunner没有告诉你的

    1.        LoadRunner之-Block l  如何在一个脚本中实现不同事务不同次数的循环呢? l  案例:假如你想在一个脚本中,实现登录执行1次,查询执行2次,插入执行3次,怎么办?录 ...

  5. Mac下好玩的终端命令

    figlet brew install figlet cowsay brew install cowsaycowsay -l: 查看所有可用动物cowsay -f daemon hello world ...

  6. C++走向远洋——(项目二、存储班长信息的学生类、派生)

    */ * Copyright (c) 2016,烟台大学计算机与控制工程学院 * All rights reserved. * 文件名:text.cpp * 作者:常轩 * 微信公众号:Worldhe ...

  7. android逆向---charles抓包

    手机与电脑处于同一网络环境,且正确设置代理后,charles显示CONNECT失败,提示信息SSL handshake with client failed: An unknown issue occ ...

  8. python 写入 execl 文件 之 xlwt 模块

    1. xlwt 安装 pip install xlwt 2. xlwt 操作, 代码 #!/usr/bin/env python3 import xlwt # 只能创建 新的 excel 文件 # 1 ...

  9. APScheduler使用总结

    安装 pip install apscheduler APScheduler组件 1.triggers(触发器) 触发器中包含调度逻辑,每个作业都由自己的触发器来决定下次运行时间.除了他们自己初始配置 ...

  10. paillier加密算法原理详解

    paillier加密算法是一种公钥加密算法,基于复合剩余类的困难问题.满足加法同态,即密文相乘等于明文相加:D(E(m1)·E(m2))=m1+m2.这里详细介绍其加密解密是如何推导的,需要具备数论. ...