Skip to content
This repository was archived by the owner on May 26, 2024. It is now read-only.

Commit d0428d5

Browse files
committed
render all books + links
1 parent 9d5d1d5 commit d0428d5

5 files changed

Lines changed: 59 additions & 2 deletions

File tree

Java Spring/Day 56/0-Omikuki Form/OmikujiForm/src/main/java/com/codingdojo/OmikujiForm/Omikuji.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,16 @@ public String handleForm(@RequestParam(value = "num") int num,
2626
@RequestParam(value = "hobby") String hobby,
2727
@RequestParam(value = "living_thing") String livingThing,
2828
@RequestParam(value = "say_something") String saySomething ,
29-
HttpSession session
29+
HttpSession session
3030
) {
3131
session.setAttribute("num", num);
3232
session.setAttribute("city", city);
3333
session.setAttribute("person_name", personName);
3434
session.setAttribute("hobby", hobby);
3535
session.setAttribute("living_thing", livingThing);
3636
session.setAttribute("say_something", saySomething );
37+
38+
// model.addAttribute("sara", num);
3739
// System.out.println(saySomething);
3840
// System.out.println(num);
3941
// System.out.println(personName);

Java Spring/Day 56/0-Omikuki Form/OmikujiForm/src/main/webapp/WEB-INF/result.jsp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111

1212
<div class="container">
1313
<h1 class="mt-4 text-center">Here's Your Omikuji!</h1>
14+
15+
<h1>${sara}</h1>
16+
17+
1418

1519
<div class="card w-50 mx-auto">
1620
<div class="card-body" style="background-color: rgba(164, 255, 255, 0.531);">

spring MVC/Day 59/2- All Books/Book/src/main/java/com/codingdojo/mvc/controllers/BookController.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.codingdojo.mvc.controllers;
22

3+
import java.util.List;
4+
35
import org.springframework.beans.factory.annotation.Autowired;
46
import org.springframework.stereotype.Controller;
57
import org.springframework.ui.Model;
@@ -21,5 +23,12 @@ public String show(@PathVariable("id") Long id , Model model ) {
2123
model.addAttribute("book",book);
2224
return "show.jsp";
2325
}
26+
//returns all books
27+
@RequestMapping("/books")
28+
public String index(Model model) {
29+
List<Book> books = bookService.allBooks();
30+
model.addAttribute("books", books);
31+
return "index.jsp";
32+
}
2433

2534
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<%@ page language="java" contentType="text/html; charset=UTF-8"
2+
pageEncoding="UTF-8"%>
3+
4+
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core"%>
5+
<!DOCTYPE html>
6+
<html>
7+
<head>
8+
<meta charset="UTF-8">
9+
<title>Show Books </title>
10+
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css" />
11+
12+
</head>
13+
<body>
14+
15+
<div class="container mt-3">
16+
<h1 class="text-center">All Books</h1>
17+
<table class="table">
18+
<thead>
19+
<tr>
20+
<th scope="col">id</th>
21+
<th scope="col"> title</th>
22+
<th scope="col">descreption</th>
23+
<th scope="col">Number of pages</th>
24+
</tr>
25+
</thead>
26+
<tbody>
27+
<c:forEach var = "book" items="${books}">
28+
<tr>
29+
<th scope="row">${book.id}</th>
30+
<td> <a href="/books/${book.id}"> ${book.title} </a></td>
31+
<td> ${book.description}</td>
32+
<td>${book.language}</td>
33+
<td>${book.numberOfPages}</td>
34+
</tr>
35+
</c:forEach>
36+
</tbody>
37+
</table>
38+
</div>
39+
40+
<script src="/webjars/bootstrap/js/bootstrap.min.js"></script>
41+
</body>
42+
</html>

spring MVC/Day 59/2- All Books/Book/src/main/webapp/WEB-INF/show.jsp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<html>
77
<head>
88
<meta charset="ISO-8859-1">
9-
<title>Show Books</title>
9+
<title>Show Book</title>
1010
<link rel="stylesheet" href="/webjars/bootstrap/css/bootstrap.min.css" />
1111

1212
</head>

0 commit comments

Comments
 (0)