Merge pull request #5583 from simbo1905/master
use of static variables is concurrency problem
This commit is contained in:
commit
1698f9d2be
|
@ -21,16 +21,13 @@ 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);
|
final int currentPage = page.orElse(1);
|
||||||
size.ifPresent(s -> pageSize = s);
|
final int pageSize = size.orElse(5);
|
||||||
|
|
||||||
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));
|
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue