Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[错误报告]: 分页查询中,Page.getRecords返回的列表所有元素均为null #6470

Open
3 tasks done
laa-1 opened this issue Sep 7, 2024 · 1 comment
Open
3 tasks done

Comments

@laa-1
Copy link

laa-1 commented Sep 7, 2024

确认

  • 我的版本是最新版本, 我的版本号与 version 相同, 并且项目里无依赖冲突
  • 我已经在 issue 中搜索过, 确认问题没有被提出过
  • 我已经修改标题, 将标题中的 描述 替换为遇到的问题

当前程序版本

3.5.7

问题描述

使用分页查询时,如果在xml文件中不指定resultType,结果集的自动映射似乎会失效,进而导致Page.getRecords返回的列表所有元素均为null(total字段和records的size是正常的)

<select id="selectByNotDeletedAndUserId">
    SELECT * FROM course WHERE deleted = 0 AND user_id = #{userId}
</select>
Page<Course> selectByNotDeletedAndUserId(Page<Course> page, Integer userId);
Page<Course> coursePage = courseMapper.selectByNotDeletedAndUserId(new Page<>(pageNum, pageSize), userId);

image
如果指定returnType,则一切正常

<select id="selectByNotDeletedAndUserId" resultType="org.example.entity.Course">
    SELECT * FROM course WHERE deleted = 0 AND user_id = #{userId}
</select>

但是在不使用分页查询,并且不指定returnType的情况下,结果集的自动映射是能正常工作的,返回的结果也是正常的。
这种不一致性会给使用者带来困惑,而且问题产生过程没有抛出任何的异常或输出警告日志,如果使用者只是漏写了returnType,排查起来非常困难

详细堆栈日志

问题产生过程中不会抛出异常,只有下游代码使用其返回结果才会出现空指针异常
@nieqiurong
Copy link
Contributor

开启下面配置.

mybatis-plus:
    configuration:
        return-instance-for-empty-row: true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants