我有这样的情况
@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());
}
但效果不佳。我的问题是,如何区分参数值。
为了实现上述场景,我不得不将我的方法更改为:
@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);
}
最佳答案
终于,我找到了我的答案。我所做的完全正确,但我在我的 URL 中传递了错误的参数。
简而言之,如果您要传递两个 Pageable,则必须有一个 @Qualifier,并且您需要相应地设置您的请求参数。
我之前在 URL 中传递的内容 http://localhost:8080/?page=0&size=2&page=0&size=3
正确的 URL 是 http://localhost:8080/?bar_page=0&bar_size=2&foo_page=0&foo_size=3
PS:无论谁拒绝了我的问题,我仍然生他/他们的气。
关于spring - 在 Spring MVC 端点中使用多个 Pageable 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43336759/