繁体   English   中英

如何在@RestController中使用Pageable?

[英]How can I use Pageable in @RestController?

我知道Pageable来自spring-data- domain。

有没有优雅的方法直接在@RestController使用org.springframework.data.domain.Pageable

我试过跟随。

@RequestMapping(method = RequestMethod.GET,
                path = "pageable",
                produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Pageable> readPageable(@NotNull final Pageable pageable) {
    return ResponseEntity.ok(pageable);
}

结果不是我的预期。

...: ~ $ curl -X GET --header 'Accept: application/json' 'http://localhost:8080/.../pageable?limit=1&offset=1' | python -mjson.tool
...
{
    "offset": 0,
    "pageNumber": 0,
    "pageSize": 20,
    "sort": null
}

它应该返回不是Pageable而是Page。

public Page<YourEntityHere> readPageable(@NotNull final Pageable pageable) {
    return someService.search(pageable);
}

Pageable是请求方,包含您需要的内容。 但Page包含结果。

例如参见链接

暂无
暂无

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

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