春季数据分页AJAX [英] Spring Data Pagination & AJAX
问题描述
我有以下控制器,我刚刚将分页包括在返回的结果中
I have the following Controller and I've just included pagination into my returned results
@RequestMapping(value = "/search/{person}", produces="application/json", method = RequestMethod.GET)
public Page<Person> findAllPersons(@PathVariable String person) {
Page<Person> list = personRepo.findAll(new PageRequest(1, PAGE_SIZE));
return list;
}
我现在试图弄清楚如何真正查看这些结果-在Person表上的搜索是它自己的AJAX请求,在UI工具上选择下一个"或上一个"可以启动它自己的GET
I'm now trying to figure out how to actually tab through these results - The search on the Person table has is it's own AJAX request, where as selecting "next" or "previous" on my UI tool can launch it's own GET
<a id="previous" href="onclick="setPageNumber(1)">
<a id="next" href="onclick="setPageNumber(2)">
function setPageNumber(num) { //relaunch request with page number value retrieved from previous or next}
我是否应该像这样将pageNumber用作 @PathVariable
:
Should I include a pageNumber as a @PathVariable
like so:
@RequestMapping(value = "/search/{person}/{pageNumber}", produces="application/json", method = RequestMethod.GET)
public Page<Person> findAllPersons(@PathVariable String person, @PathVariable int pageNumber) {
Page<Person> list = personRepo.findAll(new PageRequest(pageNumber, PAGE_SIZE));
return list;
}
还是应该将pageNumber设置为一个完全独立的控制器方法,以某种方式使用pageNumber参数调用 findAllPersons
?我可能会在这里使自己感到困惑-欢迎任何输入,谢谢!
or should setting the pageNumber be a completely separate controller method that somehow invokes findAllPersons
with the pageNumber argument? I may be confusing myself here - any input is welcome thanks!
推荐答案
对于REST服务,我会将其放在参数中,而不是URI page_start = X& page_size = Y .
For REST service I would put it to the parameters rather then to URI page_start=X&page_size=Y.
这篇关于春季数据分页AJAX的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!