Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

265
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!