简体   繁体   中英

how to make multiple REST calls to same method

I have a requirement, where I need to return list of objects from Spring REST method. But, I need to split those objects by 100.. Let's say if the response objects are more than 400, the method should be called 5 times and every time I need to send 100 objects.

How to implement this scenario? How can I explicitly make multiple calls to the same method? Is it possible?

Thanks in Advance.

The term you are looking for is pagination. One of the example ( source and more details ):

@RestController
class PersonController {

    final PersonService personService

    @Autowired
    PersonController( PersonService personService ){
        this.personService = personService
    }

    @RequestMapping(value="/persons",method=RequestMethod.GET)
    Page<Person> list( Pageable pageable){
        Page<Person> persons = personService.listAllByPage(pageable)
        persons
    } 
}

/persons?page=0&size=3 would return a batch of the first 3 persons from the database. /persons?page=1&size=3 would return the next batch.

Notice that we haven't passed RequestParams to our handler method . When the endpoint /persons?page=0&size=3 is hit, Spring would automatically resolve the page and size parameters and create a Pageable instance . We would then pass this Pageable instance to the Service layer ,which would pass it to our Repository layer .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM