Skip to content

Commit 9663cc0

Browse files
committed
orElse is cleaner
1 parent e3fc47d commit 9663cc0

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

‎spring-thymeleaf/src/main/java/com/baeldung/thymeleaf/controller/BookController.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public class BookController {
2626

2727
@RequestMapping(value = "/listBooks", method = RequestMethod.GET)
2828
public String listBooks(Model model, @RequestParam("page") Optional<Integer> page, @RequestParam("size") Optional<Integer> size) {
29-
int currentPage = page.isPresent()?page.get():5;
30-
int pageSize = size.isPresent()?size.get():1;
29+
int currentPage = page.orElse(1);
30+
int pageSize = size.orElse(5);
3131

3232
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));
3333

0 commit comments

Comments
 (0)