<!-- 加入 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


接收 前端传过来的 页码 和 条数
springBoot mybatis mysql  pagehelper layui 分页

 

 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>'
}
}
springBoot mybatis mysql  pagehelper layui 分页

layui js 代码:
springBoot mybatis mysql  pagehelper layui 分页

 

 

springBoot mybatis mysql  pagehelper layui 分页

 

 


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" >});

 html 代码:

springBoot mybatis mysql  pagehelper layui 分页

 

 

 

<table class="layui-hide" ></script>

如问题请留言 感谢观看

相关文章: