-1
I am implementing pagination in some endpoints of my API and the return is a Page
. This object returns many arguments, there is some way to eliminate some of them?
The Repository extends Jparepository
SERVICE
@Autowired
ClienteRepositoy clienteRepositoy;
public List<Cliente> findAllList() {
return clienteRepositoy.findAll();
}
CONTROLLER
@Autowired
ServiceCliente serviceCliente;
@GetMapping("/clientes")
public Page<Cliente> getClientes() {
List<Cliente> clientes = serviceCliente.findAllList();
return new PageImpl<>(convertToDto(clientes), PageRequest.of(0, 10), clientes.size());
}
RETURN JSON
{
"content": [
{
"id": 1,
"nome": "TESTE AUTOMATICO"
}
],
"pageable": {
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 10,
"paged": true,
"unpaged": false
},
"totalPages": 1,
"totalElements": 7,
"last": true,
"size": 10,
"number": 0,
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"first": true,
"numberOfElements": 7,
"empty": false
}
I would like to remove information like the whole pageable object, for example:
"pageable": {
"sort": {
"sorted": false,
"unsorted": true,
"empty": true
},
"offset": 0,
"pageNumber": 0,
"pageSize": 10,
"paged": true,
"unpaged": false
},
You were very clear. I return a list of customers and do a processing with that list before returning, as well as convert them to DTO not to expose my entity directly. If I use the
findAll(Pageable)
I’ll have to work with Pages and not with entities.– Gustavo
And the return turns out to be the same as the way I’m doing it :/
– Gustavo