Skip to content

Commit

Permalink
상품 목록
Browse files Browse the repository at this point in the history
  • Loading branch information
kiteB committed Oct 27, 2021
1 parent 58d3270 commit 3a79004
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
@@ -1,19 +1,23 @@
package jpabook.jpashop.controller;

import jpabook.jpashop.domain.item.Book;
import jpabook.jpashop.domain.item.Item;
import jpabook.jpashop.service.ItemService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
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 {

private final ItemService itemService;

//상품 등록
@GetMapping(value = "/items/new")
public String createForm(Model model) {
model.addAttribute("form", new BookForm());
Expand All @@ -33,4 +37,12 @@ public String create(BookForm form) {

return "redirect:/items";
}

//상품 목록 조회
@GetMapping(value = "/items")
public String list(Model model) {
List<Item> items = itemService.findItems();
model.addAttribute("items", items);
return "items/itemList";
}
}
34 changes: 34 additions & 0 deletions jpashop2/src/main/resources/templates/items/itemList.html
@@ -0,0 +1,34 @@
<!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>

0 comments on commit 3a79004

Please sign in to comment.