@PostMapping("/books/borrow/{id}")
public String borrowBook(@PathVariable int id, Errors errors) {
Book borrowedBook = bookRepository.findById(id);
if (borrowedBook.getAvailableCount() == 0){
errors.rejectValue("onStock", "Book out of stock. Come later...");
return "redirect:/books/?errors="+errors.getAllErrors();
}
при отображении запроса на получение
@GetMapping("/books")
public String getBooks(Model model, @RequestParam("errors") List<ObjectError> errors)
{
model.addAttribute("errors", errors);
return null;
}