Skip to content

Instantly share code, notes, and snippets.

@eugenp
Created January 15, 2012 23:29
Show Gist options
  • Save eugenp/1617963 to your computer and use it in GitHub Desktop.
Save eugenp/1617963 to your computer and use it in GitHub Desktop.
Pagination with REST - the Controller
@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();
}
@eugenp
Copy link
Author

eugenp commented Jan 29, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment