Created
January 15, 2012 23:29
-
-
Save eugenp/1617963 to your computer and use it in GitHub Desktop.
Pagination with REST - the Controller
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| @RequestMapping( value = "admin/foo",params = { "page", "size" },method = GET ) | |
| @ResponseBody | |
| public List< Foo > findPaginated( | |
| @RequestParam( "page" ) int page, @RequestParam( "size" ) int size, | |
| UriComponentsBuilder uriBuilder, HttpServletResponse response ){ | |
| Page< Foo > resultPage = service.findPaginated( page, size ); | |
| if( page > resultPage.getTotalPages() ){ | |
| throw new ResourceNotFoundException(); | |
| } | |
| eventPublisher.publishEvent( new PaginatedResultsRetrievedEvent< Foo > | |
| ( Foo.class, uriBuilder, response, page, resultPage.getTotalPages(), size ) ); | |
| return resultPage.getContent(); | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is used in:
http://www.baeldung.com/2012/01/18/rest-pagination-in-spring/