国际网站开发客户,wordpress本地化插件,哪家网站优化公司好,山西建设机械网站首页Mybatis-Plus 中的分页查询接口主要有两个#xff1a;IPage 和 Page。 IPage 接口#xff1a; IPage 是 Mybatis-Plus 中的分页结果集接口#xff0c;它继承了 Mybatis 的 RowBounds 接口#xff0c;提供了一系列的分页查询方法。该接口主要用于返回分页后的数据结果。 Pa…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。countIdcount 查询的列名默认为 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 {Autowiredprivate UserMapper userMapper;public IPageUser getUserList(int currentPage, int pageSize) {// 创建分页对象PageUser page new Page(currentPage, pageSize);// 构造查询条件QueryWrapperUser queryWrapper new QueryWrapper();queryWrapper.gt(age, 18);// 执行分页查询IPageUser userPage userMapper.selectPage(page, queryWrapper);return userPage;}
}在这个例子中我们通过构造一个 Page 对象来设置当前页和每页条数。然后通过 QueryWrapper 构造查询条件在调用 userMapper.selectPage(page, queryWrapper) 方法进行分页查询。