이번에는 홈 화면에서 <회원 조회> 버튼을 눌렀을 때 회원 목록이 뜨도록 컨트롤러를 설정해 보겠다.
MemberController.java
@GetMapping("/members")
public String list(Model model) {
List<Member> members = memberService.findMembers();
model.addAttribute("members", members);
return "members/memberList";
}
그리고 template에 memberList.html을 추가한다.
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<div class="container">
<div>
<table>
<thead>
<tr>
<th>#</th>
<th>이름</th>
</tr>
</thead>
<tbody>
<tr th:each="member : ${members}">
<td th:text="${member.id}"></td>
<td th:text="${member.name}"></td>
</tr>
</tbody>
</table>
</div>
</div> <!-- /container -->
</body>
</html>
이렇게 실행을 해서 회원가입 창에서 spring1, spring2를 등록하면 아래와 같이 목록이 뜬다.

'Framework > Spring' 카테고리의 다른 글
| 회원 웹 기능 - 등록 (0) | 2024.01.12 |
|---|---|
| 회원 웹 기능 - 홈 화면 추가 (0) | 2024.01.12 |
| 자바 코드로 직접 스프링 빈 등록하기 (0) | 2024.01.12 |
| 컴포넌트 스캔, 자동 의존관계 (0) | 2024.01.12 |
| 회원 서비스 테스트 (0) | 2024.01.09 |