简体   繁体   English

如何对同一方法进行多个REST调用

[英]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. 我有一个要求,我需要从Spring REST方法返回对象列表。 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. 但是,我需要将这些对象除以100。例如,如果响应对象超过400,则该方法应调用5次,并且每次需要发送100个对象时。

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=0&size=3将从数据库中返回前三个人的一批。 /persons?page=1&size=3 would return the next batch. /persons?page=1&size=3将返回下一批。

Notice that we haven't passed RequestParams to our handler method . 注意,我们还没有将RequestParams传递给我们的处理程序方法。 When the endpoint /persons?page=0&size=3 is hit, Spring would automatically resolve the page and size parameters and create a Pageable instance . 当命中端点/persons?page=0&size=3 ,Spring会自动解析pagesize参数并创建一个Pageable实例。 We would then pass this Pageable instance to the Service layer ,which would pass it to our Repository layer . 然后,我们将此Pageable实例传递给Service层,然后将其传递给我们的Repository层。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何同时拨打多个电话 - How to make multiple phone calls at the same time Mockito:多次调用相同的方法 - Mockito: multiple calls to the same method java-使变量在多个方法调用上持久 - java - make variable persistent on multiple method calls 如何对Amazon Alexa进行REST API调用 - How to make REST API calls to Amazon Alexa 是否存在竞争条件,或者该方法如何与多次调用同一对象的同一方法一起使用? - Will there be race conditions or how does this work with multiple calls been made to same method of the same object 具有相同参数的多个 REST API 调用的最佳实践是什么 - What is the best practice for multiple REST API calls with the same parameters 是否在编译器优化的同一语句中多次调用同一方法? - Are multiple calls to the same method in the same statement optimized by the compiler? 使用 Mockito 多次调用具有相同参数的相同方法 - Using Mockito with multiple calls to the same method with the same arguments 多次连续调用同一方法而不重复方法名 - Multiple consecutive calls of same method without repeating the method name 多次调用相同方法时取消方法调用 - Cancelling method calls when the same method is called multiple time
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM