Browse Source

Add booklist webpage, fetch results and display them

Signed-off-by: Pekka Helenius <fincer89@hotmail.com>
v0.0.1-alpha
Pekka Helenius 4 years ago
parent
commit
8d53ef4cc7
4 changed files with 34 additions and 11 deletions
  1. +1
    -1
      bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java
  2. +14
    -7
      bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java
  3. +19
    -3
      bookstore/src/main/resources/templates/booklist.html
  4. +0
    -0
      bookstore/src/main/resources/templates/index.html.old

+ 1
- 1
bookstore/src/main/java/com/fjordtek/bookstore/model/Book.java View File

@ -24,7 +24,7 @@ public class Book {
// Primary key value in database // Primary key value in database
@Id @Id
@GeneratedValue(strategy=GenerationType.AUTO)
@GeneratedValue(strategy = GenerationType.AUTO)
private long id; private long id;
//////////////////// ////////////////////


+ 14
- 7
bookstore/src/main/java/com/fjordtek/bookstore/web/BookController.java View File

@ -6,6 +6,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.web.bind.annotation.RequestParam; //import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ResponseStatus; 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.servlet.http.HttpServletRequest;
//import javax.validation.Valid; //import javax.validation.Valid;
import com.fjordtek.bookstore.model.Book;
import com.fjordtek.bookstore.model.*;
@Controller @Controller
public class BookController { public class BookController {
protected static final String landingPageURL = "index"; protected static final String landingPageURL = "index";
protected static final String bookListPageURL = "booklist";
private HttpServerLogger httpServerLogger = new HttpServerLogger(); private HttpServerLogger httpServerLogger = new HttpServerLogger();
private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler(); private HttpExceptionHandler httpExceptionHandler = new HttpExceptionHandler();
@Autowired
private BookRepository bookRepository;
@RequestMapping( @RequestMapping(
value = landingPageURL,
value = { bookListPageURL },
method = RequestMethod.GET method = RequestMethod.GET
) )
public String DefaultWebFormGet(Model dataModel, HttpServletRequest requestData) { public String DefaultWebFormGet(Model dataModel, HttpServletRequest requestData) {
//dataModel.addAttribute("book", new Book());
httpServerLogger.logMessageNormal( httpServerLogger.logMessageNormal(
requestData, requestData,
"HTTPOK" "HTTPOK"
); );
return landingPageURL;
dataModel.addAttribute("books", bookRepository.findAll());
return bookListPageURL;
} }
// Redirect // Redirect
@RequestMapping( @RequestMapping(
value = "/",
value = { "/", landingPageURL },
method = RequestMethod.GET method = RequestMethod.GET
) )
@ResponseStatus(HttpStatus.FOUND) @ResponseStatus(HttpStatus.FOUND)
public String redirectToDefaultWebForm() { public String redirectToDefaultWebForm() {
return "redirect:" + landingPageURL;
return "redirect:" + bookListPageURL;
} }
// Other URL requests // Other URL requests


+ 19
- 3
bookstore/src/main/resources/templates/booklist.html View File

@ -1,10 +1,26 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org"> <html lang="en" xmlns:th="http://www.thymeleaf.org">
<head> <head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Bookstore page</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Bookstore page</title>
</head> </head>
<body> <body>
N/A // To-be-added
<h1>Books</h1>
<table>
<tr>
<th>Author</th>
<th>Title</th>
<th>ISBN</th>
<th>Year</th>
</tr>
<tr th:each="book : ${books}">
<td th:text="${book.author}"></td>
<td th:text="${book.title}"></td>
<td th:text="${book.isbn}"></td>
<td th:text="${book.year}"></td>
</tr>
</table>
</body> </body>
</html> </html>

bookstore/src/main/resources/templates/index.html → bookstore/src/main/resources/templates/index.html.old View File


Loading…
Cancel
Save