IT评测·应用市场-qidao123.com

标题: MyBatis-Plus 分页查询接口返回值题目剖析 [打印本页]

作者: 熊熊出没    时间: 2025-3-14 20:59
标题: MyBatis-Plus 分页查询接口返回值题目剖析
在使用 MyBatis-Plus 举行分页查询时,许多开发者会遇到一个常见的题目:当分页查询接口返回值定义为 Page<T> 时,执行查询会抛出非常;而将返回值修改为 IPage<T> 时,分页查询却能正常工作。本文将从 MyBatis-Plus 的分页机制入手,详细分析这一题目的根源,并提供相应的办理方案。
<hr> 一、题目现象形貌

在 MyBatis-Plus 中,我们通常会定义一个分页查询接口,如下:
  1. Page<CommentsEntity> selectComments(IPage<CommentsEntity> page, @Param("args") CommentsPageArgs args);
复制代码
当返回值为 Page<CommentsEntity> 时,执行分页查询会抛出如下非常:
  1. Expected one result (or null) to be returned by selectOne(), but found: 10
复制代码
但是,如果将返回值修改为 IPage<CommentsEntity>,分页查询便能够正常执行。比方:
  1. IPage<CommentsEntity> selectComments(IPage<CommentsEntity> page, @Param("args") CommentsPageArgs args);
复制代码
这种现象让许多开发者感到困惑:Page<T> 不是继续自 IPage<T> 吗?为什么二者作为返回值时的表现却截然不同?
<hr> 二、MyBatis-Plus 分页机制简析

要解答这个题目,我们起首必要相识 MyBatis-Plus 的分页机制。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。




欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/) Powered by Discuz! X3.4