[김영한님의 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술] 회원 관리 예제 - 웹 MVC 개발 - '회원 웹 기능 - 조회' 수강

This commit is contained in:
banjjoknim
2020-12-23 00:38:42 +09:00
parent 34affd356d
commit 4e136d93b0
4 changed files with 47 additions and 1 deletions

View File

@@ -25,3 +25,4 @@
## 회원 관리 예제 - 웹 MVC 개발
- [회원 웹 기능 - 홈 화면 추가](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture15.md)
- [회원 웹 기능 - 등록](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture16.md)
- [회원 웹 기능 - 조회](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture17.md)

View File

@@ -0,0 +1,12 @@
# 회원 웹 기능 - 조회
---
## 템플릿 엔진
- `${키}`은 모델안에 있는 해당 키의 값을 꺼내는 것이다.
- ex. `${members}`는 모델에서 `members`라는 키에 해당하는 값을 꺼내온다.
- `th:each="member : ${members}"` : `members` 리스트의 루프를 돌면서 객체를 하나씩 `member`에 할당한 뒤, 해당 태그 내부의 로직을 실행한다. 자바의 `for-each`문과 비슷하다.
- `${member.id}` : 위에서 할당된 `member` 객체에서 `getId`를 호출한 결과값이 할당된다.
- `${member.name}` : 위에서 할당된 `member` 객체에서 `getName`를 호출한 결과값이 할당된다.
---

View File

@@ -4,9 +4,12 @@ import hello.springintroduction.domain.Member;
import hello.springintroduction.service.MemberService;
import org.springframework.beans.factory.annotation.Autowired;
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
public class MemberController {
@@ -31,4 +34,11 @@ public class MemberController {
return "redirect:/";
}
@GetMapping("/members")
public String list(Model model) {
List<Member> members = memberService.findMembers();
model.addAttribute("members", members);
return "members/memberList";
}
}

View File

@@ -0,0 +1,23 @@
<!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>