회원 웹 기능 - 조회

Sunny·2023년 2월 11일
0

1.MemberController.java 구현

    @GetMapping("/members")
    public String list(Model model) {
        List<Member> members = memberService.findMembers();
        model.addAttribute("members", members);
        return "members/memberList";
    }

2.memberList.html 구현

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <title>회원 조회</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<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>
</body>
</html>

조회가 정상적으로 된다.

아직은 db가 아닌 메모리에 저장이 되기 때문에 톰캣을 껐다가 다시 키면 조회 목록은 사라진다.

이런 일을 방지하기 위해 db에 데이터를 저장하는 과정을 다음 글에서 알아보자.

profile
개발에 재미를 붙여보기 :)

0개의 댓글