当前位置:网站首页>Paging plug-in -- PageHelper
Paging plug-in -- PageHelper
2022-07-26 23:49:00 【The most procedural ape】
mybatis The paging query of can be passed through PageHelper Plug-in implementation
In the database, we use paging query sql Statement for :
select * from Table name [where Conditions ] limit (page-1)*pageSize, pageSize;
page: The current page number
pageSize: Number of entries per page .
But when we use PageHelper We don't need to calculate the page number after the plug-in We can get what we want by directly using the functions in it . Such as : Total number of articles Total number of pages The data presented on the current page
Use steps :
First step : stay pom.xml Introduce dependency in
<dependency>
<groupId>repMaven.com.github.pagehelper</groupId>
<artifactId>pagehelper</artifactId>
<version>5.3.0</version>
</dependency>
The second step : stay conf.xml Set in PageHelper Interceptor
<plugins>
<plugin interceptor="com.github.pagehelper.PageInterceptor"></plugin>
</plugins>
Be careful :
The third step : Testing class ( unit testing ) Medium test :
@Test
public void testFindAll() throws Exception{
Reader rd = Resources.getResourceAsReader("conf.xml");
SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(rd);
SqlSession session = factory.openSession();
UserDao userDao = session.getMapper(UserDao.class);
//pageNum: The current page pageSize: How many pieces of data are displayed per page
PageHelper.startPage(1,2);
List<User> user = userDao.findAll();
PageInfo<User> pageInfo = new PageInfo<User>(user);
System.out.println(" Total number of articles :"+pageInfo.getTotal());
System.out.println(" Total number of pages :"+pageInfo.getPages());
System.out.println(" Data corresponding to the current page number :"+pageInfo.getList());
session.close();
}

The database for :
/*
Navicat Premium Data Transfer
Source Server : Michinaish
Source Server Type : MySQL
Source Server Version : 80011
Source Host : localhost:3306
Source Schema : mybatis
Target Server Type : MySQL
Target Server Version : 80011
File Encoding : 65001
Date: 06/06/2022 19:16:07
*/
SET NAMES utf8mb4;
SET FOREIGN_KEY_CHECKS = 0;
-- ----------------------------
-- Table structure for tbl_user02
-- ----------------------------
DROP TABLE IF EXISTS `tbl_user02`;
CREATE TABLE `tbl_user02` (
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT ' Primary key ID',
`name` varchar(30) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' full name ',
`pwd` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' password ',
`email` varchar(50) CHARACTER SET utf8 COLLATE utf8_general_ci NULL DEFAULT NULL COMMENT ' mailbox ',
PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 8 CHARACTER SET = utf8 COLLATE = utf8_general_ci ROW_FORMAT = Dynamic;
-- ----------------------------
-- Records of tbl_user02
-- ----------------------------
INSERT INTO `tbl_user02` VALUES (6, ' Zhang San ', '123', '[email protected]');
INSERT INTO `tbl_user02` VALUES (7, ' Li Si ', '123', '[email protected]');
INSERT INTO `tbl_user02` VALUES (9, 'ac', '123', '[email protected]');
INSERT INTO `tbl_user02` VALUES (10, 'bc', '123', '[email protected]');
INSERT INTO `tbl_user02` VALUES (11, 'cc', '123', '[email protected]');
INSERT INTO `tbl_user02` VALUES (12, 'dc', '123', '[email protected]');
SET FOREIGN_KEY_CHECKS = 1;
边栏推荐
- ES6新特性
- Upload files to OSS file server
- Tensorflow2.0 深度学习运行代码简单教程
- Embedded system migration [8] - device tree and root file system migration
- 1. Configuration environment and project creation
- pgsql -&gt; flink cdc -&gt; flink -&gt; Mysql, if a PgSQL CDC
- 文件上传到服务器
- Sign up now | frontier technology exploration: how to make spark stronger and more flexible
- 银河证券网上开户佣金,网上客户经理开户安全吗
- 第二部分—C语言提高篇_8. 文件操作
猜你喜欢

Meeting OA my meeting

第二部分—C语言提高篇_6. 多维数组

In simple terms, cchart's daily lesson - Lesson 59 of happy high school 4 comes to the same end by different ways, and the C code style of the colorful interface library

会议OA之我的会议

Part II - C language improvement_ 13. Recursive function

Download win10 system image and create virtual machine on VMware virtual machine

力扣141题:环形链表

Public cloud security and compliance considerations

文件上传到OSS文件服务器

分页插件--PageHelper
随机推荐
证券公司哪家佣金最低?网上开户安全吗
04-传统的Synchronized锁
第6节:cmake语法介绍
第二部分—C语言提高篇_6. 多维数组
简单的SQL优化
C language dynamic memory management
Silicon Valley class lesson 5 - Tencent cloud object storage and course classification management
【面试:并发篇27:多线程:犹豫模式】
企业数据治理面临的六大挑战!
np. transpose & np.expand_ dims
8 other programming languages -- Recording
Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
Embedded system migration [8] - device tree and root file system migration
Related functions of strings
[Luogu] p1395 meeting
Application of workflow engine in vivo marketing automation | engine 03
SQL Basics
Several inventory terms often used in communication
Part II - C language improvement_ 7. Structure
【不积跬步无以至千里】统计日志指定时间段内的关键词