【发布时间】:2018-12-13 22:54:40
【问题描述】:
在我的系统(Spring Boot 项目)中,我需要向每 350 个搜索我的数据的人发出请求,我需要分页并发送。我寻找了很多方法来做到这一点,并在 JPA 中找到了很多,但我使用的是 Jooq,所以我寻求用户工具的帮助,他们指导我使用限制和偏移选项。
这是我进行研究的方法,我设置了我的 DTO,最后我返回了人员列表。
public static ArrayList getAllPeople(Connection connection) {
ArrayList<peopleDto> peopleList = new ArrayList<>();
DSLContext ctx = null;
peopleDto peopleDto;
try {
ctx = DSL.using(connection, SQLDialect.MYSQL);
Result<Record> result = ctx.select()
.from(people)
.orderBy(people.GNUM)
.offset(0)
.limit(350)
.fetch();
for (Record r : result) {
peopleDto = new peopleDto();
peopleDto.setpeopleID(r.getValue(people.GNUM));
peopleDto.setName(r.get(people.SNAME));
peopleDto.setRM(r.get(people.SRM));
peopleDto.setRG(r.get(people.SRG));
peopleDto.setCertidaoLivro(r.get(people.SCERT));
peopleDto.setCertidaoDistrito(r.get(people.SCERTD));
peopleList.add(peopleDto);
}
} catch (Exception e) {
log.error(e.toString());
} finally {
if (ctx != null) {
ctx.close();
}
}
return peopleList;
}
此搜索没有限制返回 1,400 人。 问题是我如何发送限制数然后返回到这个方法继续我上次离开的地方,直到我达到记录的总值?
【问题讨论】:
-
看看这篇文章以及如何使用查询结果创建一个新的pageimpl petrikainulainen.net/programming/jooq/…
-
已经试过了,作者用了折旧的方法,没用
-
我认为带有 PageImpl 的部分仍然有效,不是吗?
-
不相关:如果您将
connection传递给它,您不必关闭您的DSLContext- 在这种情况下它不是资源丰富。
标签: java spring-boot jooq