【发布时间】:2018-09-20 10:04:27
【问题描述】:
在使用联合查询时,有没有更好的方法来处理 mybatis 分页? 不要认为这是一个强大的用例,而只是代表我的实际问题。
我需要进行联合才能从 2 个不同的表中获取记录。
这里的问题是,如果我将 pageSize 设置为 100,例如,如果 10 个学生每人有 20 条记录,那么即使有 200 条记录,我也只能得到 100 条记录。在下面的示例课程中,当我打印每个学生的记录数时,我不会看到所有记录。
例如-
<code>
with student AS (
select * from std (
select studentId, name, class, ROW_NUMBER() over (order by studentId) as paginationRank from Student
)std
where paginationRank > #{ _skipRows} and paginationRank <= ( #{_pageSize} *
(#{_page}+1))
)
select student.studentId, attendanceRegfields......Creditsfields....
from student left outer join
( select ..... from attendanceReg
union all
select .... from Credits ) all_records
on all_records.studentId = student.studentId
</code>
在我的项目编写器中,如果我得到所有学生记录
<code>
class MyItemWriter extends ItemWriter<Student>
{
write(List<student> studentRecords){
Map<String, List<Student>> studentRecordsMap =
studentRecords.stream().collect(groupby(e-> e.getStudentId()));
studentRecordsMap .forEach((key, studentRecords) -> process(stuedntRecords);
}
process(List<Student> studentRecords){
// here I am processing all records
}
}
</code>
【问题讨论】:
-
请显示
std表的定义以及查询到Student(我假设)类的mybatis映射。 -
感谢您的快速响应,我无法从我的应用程序中获取相同的 sql,请理解问题,如果您有任何问题,请询问我。
-
你不需要展示真实的表格和真实的映射。重现该问题的综合示例甚至更好(请参阅stackoverflow.com/help/mcve)。没有这些信息,问题就很难定义。
标签: spring oracle spring-batch mybatis