Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

257
Vistas
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);
}
about 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

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.

about 4 years ago · Santiago Trujillo Denunciar

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());
}`
about 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda