Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

266
Visualizações
Use multiple Pageable parameters in Spring MVC endpoint

I have a situation like this

@Autowired
private CustomerRepository repo;

@RequestMapping("/")
public Page<Customer> getDocuments(@Qualifier("bar") Pageable pageable,
                                   @Qualifier("foo")Pageable pageable2)
{
    return repo.findAll(pageable,pageable2.getOffset(), pageable2.getPageSize());
}

but it did not work well. My question is, how can I distinguish between the parameter values.

To achieve the above scenario I had to change my method to this:

@RequestMapping("/")
public Page<Customer> getDocuments(Pageable pageable,
                                   @RequestParam(value="from", defaultValue="0") int offSet,
                                   @RequestParam(value="length", defaultValue="3") int length)
{
    return repo.findAll(pageable, offSet, length);
}
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Finally, I have found my answer. What I did was absolutely correct but I was passing the wrong parameters in my URL.

In short, if you are passing two Pageable there has to be a @Qualifier and you need to set your request parameter accordingly.

what I was passing before in URL http://localhost:8080/?page=0&size=2&page=0&size=3 and the correct URL would be http://localhost:8080/?bar_page=0&bar_size=2&foo_page=0&foo_size=3

PS: whoever downvoted my question I am still mad at him/them.

over 4 years ago · Santiago Trujillo Relatório

0

I think it is wrong idea to pass Spring beans as argument to rest resource. If the values needs to be accessed from Bean, then it should access inside the resource assuming bean is already initialized.

`@Autowired private CustomerRepository repo;

@Autowired
@Qualifier("bar")
Pageable pageable;

@Autowired
@Qualifier("foo")
Pageable pageable2;

@RequestMapping("/")
 public Page<Customer> getDocuments(){

   return     repo.findAll(pageable,pageable2.getOffset(),pageable2.getPageSize());
}`
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda