[英]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会自动解析page和size参数并创建一个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.