当前位置:网站首页>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;
边栏推荐
- Custom type
- Problems and solutions encountered in using nextline(), nextint() and next() in scanner
- 2022年物联网行业有哪些用例?
- Upload files to OSS file server
- Sign up now | frontier technology exploration: how to make spark stronger and more flexible
- Silicon Valley class lesson 7 - Tencent cloud on demand management module (2)
- 力扣152题:乘积最大子数组
- 数据供应链的转型 协调一致走向成功的三大有效策略
- [H5 bottom scrolling paging loading]
- 【面试:并发篇26:多线程:两阶段终止模式】volatile版本
猜你喜欢

Silicon Valley class lesson 5 - Tencent cloud object storage and course classification management

Part II - C language improvement_ 12. Packaging and use of dynamic / precision Library

Machine learning notes - building recommendation system (3) six research directions of deep recommendation system

C language array

Problems and solutions encountered in using nextline(), nextint() and next() in scanner

np.transpose & np.expand_dims

Part II - C language improvement_ 8. File operation

Silicon Valley class lesson 6 - Tencent cloud on demand management module (I)

Pyqt5 how to set pushbutton click event to obtain file address

Product principles of non-financial decentralized application
随机推荐
买不到的数目
ES6新特性
【不积跬步无以至千里】统计日志指定时间段内的关键词
Pyqt5 how to set pushbutton click event to obtain file address
04 traditional synchronized lock
上千Tile的倾斜模型浏览提速,告别一块一块往外蹦的尴尬
Pytorch learning record (II): tensor
Vector execution engine framework gluten announced the official open source and appeared at spark technology summit
Novice online interview [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
The nature and proof of the center of gravity of [mathematics] tree
Question 152: product maximum subarray
分页插件--PageHelper
Three effective strategies for the transformation of data supply chain to be coordinated and successful
Dajiang Zhitu and CC have produced multiple copies of data. How to combine them into one and load them in the new earth map
[shader realizes swaying effect _shader effect Chapter 4]
Re understand the life world and ourselves
Interview questions of Bank of Hangzhou [Hangzhou multi tester] [Hangzhou multi tester _ Wang Sir]
第二部分—C语言提高篇_13. 递归函数
Pre research of data quality management tools Griffin vs deequ vs great expectations vs quality
Public cloud security and compliance considerations