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 d5f153b commit a7a0e13
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
10 changes: 10 additions & 0 deletions jpashop2/src/main/java/jpabook/jpashop/web/MemberController.java
Expand Up @@ -11,13 +11,15 @@
import org.springframework.web.bind.annotation.PostMapping;

import javax.validation.Valid;
import java.util.List;

@Controller
@RequiredArgsConstructor
public class MemberController {

private final MemberService memberService;

//회원 등록
@GetMapping("/members/new")
public String createForm(Model model) {
model.addAttribute("memberForm", new MemberForm());
Expand All @@ -41,4 +43,12 @@ public String create(@Valid MemberForm form, BindingResult result) {

return "redirect:/";
}

//회원 목록 조회
@GetMapping(value = "/members")
public String list(Model model) {
List<Member> members = memberService.findMembers();
model.addAttribute("members", members);
return "members/memberList";
}
}
32 changes: 32 additions & 0 deletions jpashop2/src/main/resources/templates/members/memberList.html
@@ -0,0 +1,32 @@
<!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="member : ${members}">
<td th:text="${member.id}"></td>
<td th:text="${member.name}"></td>
<td th:text="${member.address?.city}"></td>
<td th:text="${member.address?.street}"></td>
<td th:text="${member.address?.zipcode}"></td>
</tr>
</tbody>
</table>
</div>
<div th:replace="fragments/footer :: footer" />
</div> <!-- /container -->
</body>
</html>

0 comments on commit a7a0e13

Please sign in to comment.