diff --git a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java index d58c846..dce45ab 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java @@ -24,7 +24,7 @@ public class Book { // Primary key value in database @Id - @GeneratedValue(strategy=GenerationType.AUTO) + @GeneratedValue(strategy = GenerationType.AUTO) private long id; //////////////////// 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 493ab97..cbc5781 100644 --- a/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java +++ b/bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java @@ -6,6 +6,7 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; +import org.springframework.beans.factory.annotation.Autowired; //import org.springframework.web.bind.annotation.RequestParam; import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.ResponseStatus; @@ -15,41 +16,47 @@ import org.springframework.web.bind.annotation.ResponseStatus; import javax.servlet.http.HttpServletRequest; //import javax.validation.Valid; -import com.fjordtek.bookstore.model.Book; +import com.fjordtek.bookstore.model.*; @Controller public class BookController { + + protected static final String landingPageURL = "index"; + protected static final String bookListPageURL = "booklist"; private HttpServerLogger httpServerLogger = new HttpServerLogger(); private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler(); + @Autowired + private BookRepository bookRepository; + @RequestMapping( - value = landingPageURL, + value = { bookListPageURL }, method = RequestMethod.GET ) public String DefaultWebFormGet(Model dataModel, HttpServletRequest requestData) { - //dataModel.addAttribute("book", new Book()); - httpServerLogger.logMessageNormal( requestData, "HTTPOK" ); - return landingPageURL; + dataModel.addAttribute("books", bookRepository.findAll()); + + return bookListPageURL; } // Redirect @RequestMapping( - value = "/", + value = { "/", landingPageURL }, method = RequestMethod.GET ) @ResponseStatus(HttpStatus.FOUND) public String redirectToDefaultWebForm() { - return "redirect:" + landingPageURL; + return "redirect:" + bookListPageURL; } // Other URL requests diff --git a/bookstore/src/main/resources/templates/booklist.html b/bookstore/src/main/resources/templates/booklist.html index 67c9b42..78f131b 100644 --- a/bookstore/src/main/resources/templates/booklist.html +++ b/bookstore/src/main/resources/templates/booklist.html @@ -1,10 +1,26 @@ - - Bookstore page + +Bookstore page - N/A // To-be-added +

Books

+ + + + + + + + + + + + + + +
AuthorTitleISBNYear
+ diff --git a/bookstore/src/main/resources/templates/index.html b/bookstore/src/main/resources/templates/index.html.old similarity index 100% rename from bookstore/src/main/resources/templates/index.html rename to bookstore/src/main/resources/templates/index.html.old