jpashop : itemList view, controller
This commit is contained in:
@@ -9,6 +9,8 @@ import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Controller
|
||||
@RequiredArgsConstructor
|
||||
public class ItemController {
|
||||
@@ -31,6 +33,13 @@ public class ItemController {
|
||||
book.setIsbn(form.getIsbn());
|
||||
|
||||
itemService.saveItem(book);
|
||||
return "redirect:/";
|
||||
return "redirect:/items";
|
||||
}
|
||||
|
||||
@GetMapping("/items")
|
||||
public String list(Model model) {
|
||||
List<Item> items = itemService.findItem();
|
||||
model.addAttribute("items", items);
|
||||
return "items/itemList";
|
||||
}
|
||||
}
|
||||
|
||||
35
jpashop/src/main/resources/templates/items/itemList.html
Normal file
35
jpashop/src/main/resources/templates/items/itemList.html
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE HTML>
|
||||
<html xmlns:th="http://www.thymeleaf.org">
|
||||
<head th:replace="fragments/header :: header" />
|
||||
<body>
|
||||
<div class="container">
|
||||
<div th:replace="fragments/bodyHeader :: bodyHeader"/>
|
||||
<div>
|
||||
<table class="table table-striped">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>#</th>
|
||||
<th>상품명</th>
|
||||
<th>가격</th>
|
||||
<th>재고수량</th>
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr th:each="item : ${items}">
|
||||
<td th:text="${item.id}"></td>
|
||||
<td th:text="${item.name}"></td>
|
||||
<td th:text="${item.price}"></td>
|
||||
<td th:text="${item.stockQuantity}"></td>
|
||||
<td>
|
||||
<a href="#" th:href="@{/items/{id}/edit (id=${item.id})}"
|
||||
class="btn btn-primary" role="button">수정</a>
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div th:replace="fragments/footer :: footer"/>
|
||||
</div> <!-- /container -->
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user