diff --git a/SpringBoot-Introduction/Lectures/Contents.md b/SpringBoot-Introduction/Lectures/Contents.md index 16d8b6c..33a895f 100644 --- a/SpringBoot-Introduction/Lectures/Contents.md +++ b/SpringBoot-Introduction/Lectures/Contents.md @@ -24,4 +24,5 @@ ## 회원 관리 예제 - 웹 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) \ No newline at end of file +- [회원 웹 기능 - 등록](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture16.md) +- [회원 웹 기능 - 조회](https://github.com/banjjoknim/TIL/blob/master/SpringBoot-Introduction/Lectures/Lecture17.md) \ No newline at end of file diff --git a/SpringBoot-Introduction/Lectures/Lecture17.md b/SpringBoot-Introduction/Lectures/Lecture17.md new file mode 100644 index 0000000..41b67bb --- /dev/null +++ b/SpringBoot-Introduction/Lectures/Lecture17.md @@ -0,0 +1,12 @@ +# 회원 웹 기능 - 조회 + +--- + +## 템플릿 엔진 +- `${키}`은 모델안에 있는 해당 키의 값을 꺼내는 것이다. + - ex. `${members}`는 모델에서 `members`라는 키에 해당하는 값을 꺼내온다. +- `th:each="member : ${members}"` : `members` 리스트의 루프를 돌면서 객체를 하나씩 `member`에 할당한 뒤, 해당 태그 내부의 로직을 실행한다. 자바의 `for-each`문과 비슷하다. +- `${member.id}` : 위에서 할당된 `member` 객체에서 `getId`를 호출한 결과값이 할당된다. +- `${member.name}` : 위에서 할당된 `member` 객체에서 `getName`를 호출한 결과값이 할당된다. + +--- \ No newline at end of file diff --git a/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java b/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java index e8eb31e..67fb7c7 100644 --- a/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java +++ b/SpringBoot-Introduction/src/main/java/hello/springintroduction/controller/MemberController.java @@ -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 members = memberService.findMembers(); + model.addAttribute("members", members); + return "members/memberList"; + } } diff --git a/SpringBoot-Introduction/src/main/resources/templates/members/memberList.html b/SpringBoot-Introduction/src/main/resources/templates/members/memberList.html new file mode 100644 index 0000000..31aaf5e --- /dev/null +++ b/SpringBoot-Introduction/src/main/resources/templates/members/memberList.html @@ -0,0 +1,23 @@ + + + +
+
+ + + + + + + + + + + + + +
#이름
+
+
+ + \ No newline at end of file