Merge pull request #5583 from simbo1905/master

use of static variables is concurrency problem
This commit is contained in:
Loredana Crusoveanu 2018-11-30 11:11:00 +02:00 committed by GitHub
commit 1698f9d2be
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 3 additions and 6 deletions

View File

@ -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));