当前位置:网站首页>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;
边栏推荐
- Force deduction 155 questions, minimum stack
- Number that cannot be bought
- 30、 Modern storage system (management database and distributed storage system)
- 1. Configuration environment and project creation
- 第二部分—C语言提高篇_9. 链表
- ES6新特性
- Distributed lock and its implementation
- Tensorflow2.0 深度学习运行代码简单教程
- The nature and proof of the center of gravity of [mathematics] tree
- 第二部分—C语言提高篇_13. 递归函数
猜你喜欢

Azure Synapse Analytics 性能优化指南(4)——使用结果集缓存优化性能

Silicon Valley class lesson 7 - Tencent cloud on demand management module (2)

Part II - C language improvement_ 13. Recursive function

04-传统的Synchronized锁

动态sql

第二部分—C语言提高篇_13. 递归函数

Azure Synapse Analytics 性能优化指南(3)——使用具体化视图优化性能(下)

Thousands of tiles' tilt model browsing speeds up, saying goodbye to the embarrassment of jumping out one by one

嵌入式系统移植【8】——设备树和根文件系统移植

关于可穿戴式NFT你应该知道的一切!
随机推荐
使用AW9523B芯片驱动16路LED时,LED出现误点亮的问题
Embedded system migration [8] - device tree and root file system migration
[MySQL] CentOS 7.9 installation and use mysql-5.7.39 binary version
[Luogu] p1395 meeting
Related functions of strings
How to transfer the GPX data collected by CTI RTK out of KML and SHP with attributes for subsequent management and analysis
[Luogu] p2341 popular cattle
My SQL is OK. Why is it still so slow? MySQL locking rules
Differences between PHP round and sprintf functions
2022.7.26-----leetcode.1206
如何使用数据管道实现测试现代化
Product principles of non-financial decentralized application
np. transpose & np.expand_ dims
Pre research of data quality management tools Griffin vs deequ vs great expectations vs quality
The NFT market pattern has not changed. Can okaleido set off a new round of waves?
30、 Modern storage system (management database and distributed storage system)
pgsql -&gt; flink cdc -&gt; flink -&gt; Mysql, if a PgSQL CDC
Part II - C language improvement_ 6. Multidimensional array
Kingbasees SQL language reference manual of Jincang database (3.1.1.3. currency type)
[H5 bottom scrolling paging loading]