Skip to content

Instantly share code, notes, and snippets.

@trickyBytes
Last active January 23, 2019 15:03
Show Gist options
  • Save trickyBytes/2be0c14ba5a463fa2b1e7a3e18745d98 to your computer and use it in GitHub Desktop.
Save trickyBytes/2be0c14ba5a463fa2b1e7a3e18745d98 to your computer and use it in GitHub Desktop.
Pagination on service end-point
@PreAuthorize("hasAuthority('MOBILE_DEVICE')")
@GetMapping(path = uriListAssets)
@ResponseStatus(code = HttpStatus.OK)
public List<Asset> getAssets(@RequestParam(name = "page", required = false) Optional<Integer> page,
@RequestParam(name = "numOfResults", required = false) Optional<Integer> numOfResults) {
List<Asset> assets;
if (page.isPresent() && numOfResults.isPresent()) {
assets = assetRepository.findAll(PageRequest.of(page.get(), numOfResults.get())).getContent();
} else {
assets = assetRepository.findAll();
}
return assets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment