From 71d5c71fdfd956606e110402da2ef6983eef13df Mon Sep 17 00:00:00 2001 From: Pekka Helenius Date: Sun, 13 Sep 2020 02:47:16 +0300 Subject: [PATCH] Get current year for new books Signed-off-by: Pekka Helenius --- .../com/fjordtek/bookstore/web/BookController.java | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java index bbf4e58..3a045fa 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java @@ -13,6 +13,8 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; +import java.time.Year; + import javax.servlet.http.HttpServletRequest; import com.fjordtek.bookstore.model.*; @@ -63,7 +65,13 @@ public class BookController { bookAddPageURL + ": " + "HTTPOK" ); - dataModel.addAttribute("book", new Book()); + Book newBook = new Book(); + + dataModel.addAttribute("book", newBook); + + if (newBook.getYear() == 0) { + newBook.setYear(Year.now().getValue()); + } return bookAddPageURL; }