orElse is cleaner

This commit is contained in:
Simon Massey 2018-10-30 23:03:08 +00:00
parent e3fc47dd53
commit 9663cc09a1
1 changed files with 2 additions and 2 deletions

View File

@ -26,8 +26,8 @@ public class BookController {
@RequestMapping(value = "/listBooks", method = RequestMethod.GET)
public String listBooks(Model model, @RequestParam("page") Optional<Integer> page, @RequestParam("size") Optional<Integer> size) {
int currentPage = page.isPresent()?page.get():5;
int pageSize = size.isPresent()?size.get():1;
int currentPage = page.orElse(1);
int pageSize = size.orElse(5);
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));