removed race condition between different requests
This commit is contained in:
parent
b09fd15345
commit
aedf3b5cb5
@ -2,6 +2,7 @@ package com.baeldung.thymeleaf.controller;
|
|||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.IntStream;
|
import java.util.stream.IntStream;
|
||||||
|
|
||||||
@ -21,18 +22,18 @@ import com.baeldung.thymeleaf.service.BookService;
|
|||||||
@Controller
|
@Controller
|
||||||
public class BookController {
|
public class BookController {
|
||||||
|
|
||||||
private static int currentPage = 1;
|
|
||||||
private static int pageSize = 5;
|
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
private BookService bookService;
|
private BookService bookService;
|
||||||
|
|
||||||
@RequestMapping(value = "/listBooks", method = RequestMethod.GET)
|
@RequestMapping(value = "/listBooks", method = RequestMethod.GET)
|
||||||
public String listBooks(Model model, @RequestParam("page") Optional<Integer> page, @RequestParam("size") Optional<Integer> size) {
|
public String listBooks(Model model, @RequestParam("page") Optional<Integer> page, @RequestParam("size") Optional<Integer> size) {
|
||||||
page.ifPresent(p -> currentPage = p);
|
AtomicInteger currentPage = new AtomicInteger(1);
|
||||||
size.ifPresent(s -> pageSize = s);
|
AtomicInteger pageSize = new AtomicInteger(5);
|
||||||
|
page.ifPresent(p -> currentPage.set(p));
|
||||||
|
size.ifPresent(s -> pageSize.set(s));
|
||||||
|
|
||||||
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));
|
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage.get() - 1, pageSize.get()));
|
||||||
|
|
||||||
model.addAttribute("bookPage", bookPage);
|
model.addAttribute("bookPage", bookPage);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user