1

I basically need to create an ordered pagination through a list of objects. I ended up creating a method that returns the pagination, although the ordering is still not working, I would like to know if there is any other better way that is, i'm using Java 11.

private Page<UsuarioDto> paginationUsuariosDto(List<UsuarioDto> usuarios, Integer page, Integer size, Sort sort) {
    PageRequest pageable = PageRequest.of(page, size, sort);
    int max = (size*(page+1)>usuarios.size()) ? usuarios.size() : size*(page+1);
    Page<UsuarioDto> usuarioDtoPage = new PageImpl<>(usuarios.subList(page * size, max), pageable, usuarios.size());
    return usuarioDtoPage;
}

0 Answers0