It won't hurt to try

[스프링 입문]17.회원 웹 기능 - 조회 본문

JAVA/스프링 입문

[스프링 입문]17.회원 웹 기능 - 조회

yongki.doki 2021. 8. 14. 22:33

thymeleaf를 사용해서 회원의 아이디와 이름을 출력하는 화면이다.

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
  <meta charset="UTF-8">
  <title>Members</title>
</head>
<body>
<div class="container">
    <table>
      <thead>
        <tr>
          <th>#</th>
          <th>이름</th>
        </tr>
      </thead>
      <tbody>
        <tr th:each="member: ${members}">
          <td th:text="${member.getId()}"></td>
          <td th:text="${member.getName()}"></td>
          <br>
        </tr>
      </tbody>
    </table>
  </div>

</body>
</html>

member.getId() 대신에 member.id라고 적어도 된다.

자바의 property방식인 getter/setter이기 때문에 id에 접근할때 getId()에 접근하게 된다.

 

th:each를 사용하면 loop문을 사용할수 있게 된다.

 

자세한 사용방법은 밑의 자료처럼 thymeleaf iteration관련한 여러 자료들을 참조하면 좋다.

https://www.baeldung.com/thymeleaf-iteration

 

 


단축키

Shift + option + ↑/↓: 행 이동 

Cmd + e : 최근에 본 리소스들 확인

300x250
300x250
Comments