1
I’m new to Spring and web development and I’m having problems paging a select, this is the method that makes 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?());
}
Besides the doubt about what is the last parameter of the returned Pageimpl, I have also doubts about how to manipulate the return of this method, I tried this 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());