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
public class BookController {
private static int currentPage = 1;
private static int pageSize = 5;
@Autowired
private BookService bookService;
@RequestMapping(value = "/listBooks", method = RequestMethod.GET)
public String listBooks(Model model, @RequestParam("page") Optional<Integer> page, @RequestParam("size") Optional<Integer> size) {
page.ifPresent(p -> currentPage = p);
size.ifPresent(s -> pageSize = s);
final int currentPage = page.orElse(1);
final int pageSize = size.orElse(5);
Page<Book> bookPage = bookService.findPaginated(PageRequest.of(currentPage - 1, pageSize));