一、SpringBoot 整合 mybatis-pagehelper
1.引入分页插件依赖
<!--pagehelper --> <dependency> <groupId>com.github.pagehelper</groupId> <artifactId>pagehelper-spring-boot-starter</artifactId> <version>1.2.12</version> </dependency>
2.配置 yml
api目录路径:src/main/resources/application.yml
# 分页插件配置
pagehelper:
helperDialect: mysql
supportMethodsArguments: true
3.使用分页插件
/** * page: 第几页 * pageSize: 每页显示条数 */ PageHelper.startPage(page, pageSize);
4.分页数据封装到PagedGridResult.java传给前端
PageInfo<?> pageList = new PageInfo<>(list); PagedGridResult grid = new PagedGridResult(); grid.setPage(page); grid.setRows(list); grid.setTotal(pageList.getPages()); grid.setRecords(pageList.getTotal());
二、查询商品评论-分页
1、数据表
create table `foodie-shop-dev`.items_comments ( id varchar(64) not null comment ‘id主键‘ primary key, user_id varchar(64) null comment ‘用户id 用户名须脱敏‘, item_id varchar(64) not null comment ‘商品id‘, item_name varchar(64) null comment ‘商品名称‘, item_spec_id varchar(64) null comment ‘商品规格id 可为空‘, sepc_name varchar(32) null comment ‘规格名称 可为空‘, comment_level int not null comment ‘评价等级 1:好评 2:中评 3:差评‘, content varchar(128) not null comment ‘评价内容‘, created_time datetime null comment ‘创建时间‘, updated_time datetime null comment ‘更新时间‘ ) comment ‘商品评价表 ‘ charset = utf8mb4;
create table `foodie-shop-dev`.users ( id varchar(64) not null comment ‘主键id 用户id‘ primary key, username varchar(32) not null comment ‘用户名 用户名‘, password varchar(64) not null comment ‘密码 密码‘, nickname varchar(32) null comment ‘昵称 昵称‘, realname varchar(128) null comment ‘真实姓名‘, face varchar(1024) not null comment ‘头像‘, mobile varchar(32) null comment ‘手机号 手机号‘, email varchar(32) null comment ‘邮箱地址 邮箱地址‘, sex int null comment ‘性别 性别 1:男 0:女 2:保密‘, birthday date null comment ‘生日 生日‘, created_time datetime not null comment ‘创建时间 创建时间‘, updated_time datetime not null comment ‘更新时间 更新时间‘ ) comment ‘用户表 ‘ charset = utf8mb4;
分页查询 - SpringBoot 整合 mybatis-pagehelper
原文:https://www.cnblogs.com/callbin/p/14489186.html