2026世界杯_2004年世界杯 - 1606811.com

首页 > 开幕式世界杯 > Mybatis-Plus的IPage和Page

Mybatis-Plus的IPage和Page

Mybatis-Plus 中的分页查询接口主要有两个:IPage 和 Page。

IPage 接口:

IPage 是 Mybatis-Plus 中的分页结果集接口,它继承了 Mybatis 的 RowBounds 接口,提供了一系列的分页查询方法。该接口主要用于返回分页后的数据结果。

Page 类:

Page 类是 IPage 接口的默认实现类,实现了 IPage 接口中的方法。在进行分页查询时,通常会创建一个 Page 对象,并设置相关的分页参数。

以下是 IPage 和 Page 类的常用参数:

current:当前页数,必须大于等于 1,默认值为 1。size:每页条数,默认值为 10。total:总条数,默认值为 0。records:当前页数据集合,默认值为空集合。searchCount:是否进行 count 查询,默认值为 true,表示会统计总条数。pages:总页数,通过计算得出。optimizeCountSql:是否优化 count 查询,默认值为 true。hitCount:是否对 count 进行 limit 优化,默认值为 false。countId:count 查询的列名,默认为 null,表示所有列。maxLimit:设置最大的 limit 查询限制,默认值为 -1,表示不限制。

举个栗子:

import com.baomidou.mybatisplus.core.metadata.IPage;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.stereotype.Service;

@Service

public class UserService {

@Autowired

private UserMapper userMapper;

public IPage getUserList(int currentPage, int pageSize) {

// 创建分页对象

Page page = new Page<>(currentPage, pageSize);

// 构造查询条件

QueryWrapper queryWrapper = new QueryWrapper<>();

queryWrapper.gt("age", 18);

// 执行分页查询

IPage userPage = userMapper.selectPage(page, queryWrapper);

return userPage;

}

}

在这个例子中,我们通过构造一个 Page 对象来设置当前页和每页条数。然后通过 QueryWrapper 构造查询条件,在调用 userMapper.selectPage(page, queryWrapper) 方法进行分页查询。




在实际应用中,出现电机过载现象时为什么电流会迅速超出额定值?
《神武4》中那些效率的快捷键盘点