I'm new to Spring and web development and I'm having trouble paging a select, this is the method that does the search:
public static Page getAllPeople(Connection connection, Pageable pageable) {
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(pageable.getOffset())
.limit(pageable.getPageSize())
.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 new PageImpl(peopleList, pageable, aquiVaiOtotaldaPesquisa?());
}
In addition to the question about what is the last parameter of the returned PageImpl, I also have doubts about how to handle the return of this method, I tried that way but it does not work as expected
Page<PeopleDto> page = AlunoManager.getAllPeople(con,PageRequest.of(páginas, tamanho));//?
if(page.hasNext())
getAllPeople(connection, page.nextPageable());