map 데이터를 출력하여 보자.
컨트롤러에서 데이터를 보낸다.
@GetMapping("/th-map")
public String thMap(Model model) {
Map<String, Integer> score = new HashMap<>();
score.put("userA", 100);
score.put("userB", 90);
score.put("userC", 50);
model.addAttribute("score", score);
return "view/th-map";
}
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="utf-8">
</head>
<body>
<h2>th map</h2>
<div>
<p>
<span>userA</span>
<span th:text="${score['userA']}"></span>
</p>
<hr>
<p th:each="entry : ${score}">
<span th:text="${entry.key}"></span>
<span th:text="${entry.value}"></span>
</p>
</div>
</body>
</html>
th:text="${score['userA']}" 이렇게 특정값을 바로 받을 수 있고,
th:each 를 통해 반복할 수도 있다.
결과 화면
'프로그래밍 > thymeleaf' 카테고리의 다른 글
타임리프(thymeleaf) 링크 URL 표현식 @{} (0) | 2021.09.28 |
---|---|
타임리프(thymeleaf) 선택 변수 표현식 *{} (0) | 2021.09.17 |
타임리프(thymeleaf) 텍스트 출력 (0) | 2021.09.12 |
타임리프(thymeleaf) th:each, 변수 표현식: ${...} (0) | 2021.09.04 |
타임리프(thymeleaf) (0) | 2021.09.03 |