Mybatis-plus怎么对一个查询好的Map对象进行分页查询
时间: 2024-06-10 21:10:08 浏览: 19
可以使用Mybatis-plus提供的Page对象来实现分页查询。具体步骤如下:
1. 创建一个Page对象并设置分页参数,如当前页码和每页显示数量。
```java
Page<Map<String, Object>> page = new Page<>(1, 10);
```
2. 调用Mybatis-plus提供的selectMapsPage方法进行分页查询,该方法返回一个IPage对象,其中包含查询结果和分页信息。
```java
IPage<Map<String, Object>> result = mybatisPlusMapper.selectMapsPage(page, queryWrapper);
```
3. 从IPage对象中获取查询结果和分页信息,如当前页码、每页显示数量、总记录数等。
```java
List<Map<String, Object>> records = result.getRecords();
long total = result.getTotal();
int current = (int) result.getCurrent();
int size = (int) result.getSize();
```
完整示例代码:
```java
Page<Map<String, Object>> page = new Page<>(1, 10);
QueryWrapper<User> queryWrapper = new QueryWrapper<>();
queryWrapper.eq("age", 18);
IPage<Map<String, Object>> result = userMapper.selectMapsPage(page, queryWrapper);
List<Map<String, Object>> records = result.getRecords();
long total = result.getTotal();
int current = (int) result.getCurrent();
int size = (int) result.getSize();
```
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)