问题
I know the Pageable
comes from spring-data-
domain.
Is there any elegant way to directly use org.springframework.data.domain.Pageable
in @RestController
?
I tried following.
@RequestMapping(method = RequestMethod.GET,
path = "pageable",
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Pageable> readPageable(@NotNull final Pageable pageable) {
return ResponseEntity.ok(pageable);
}
The result is not what I expected.
...: ~ $ 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
}
回答1:
It should return not Pageable but Page.
public Page<YourEntityHere> readPageable(@NotNull final Pageable pageable) {
return someService.search(pageable);
}
Pageable is request side which contains what exactly you need. But Page contains results.
See for example the link
来源:https://stackoverflow.com/questions/47087415/how-can-i-use-pageable-in-restcontroller