728x90
Controller
@GetMapping("/literal")
public String literal(Model model) {
model.addAttribute("data","Spring!");
return "basic/literal";
}
HTML
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1>리터럴</h1>
<ul>
<!--주의! 다음 주석을 풀면 예외가 발생함-->
<!-- <li>"hello world!" = <span th:text="hello world!"></span></li>-->
<li>'hello' + ' world!' = <span th:text="'hello' + ' world!'"></span></li>
<li>'hello world!' = <span th:text="'hello world!'"></span></li>
<li>'hello ' + ${data} = <span th:text="'hello ' + ${data}"></span></li>
<li>리터럴 대체 |hello ${data}| = <span th:text="|hello ${data}|"></span></li>
</ul>
</body>
</html>

728x90
'백엔드 > 타임리프' 카테고리의 다른 글
| 타임리프 속성 값 설정 (0) | 2021.09.12 |
|---|---|
| 타임리프 연산 (0) | 2021.09.12 |
| 타임리프 URL 링크 (0) | 2021.09.11 |
| 타임리프 유틸리티 객체와 날짜 (0) | 2021.09.11 |
| 타임리프 기본객체(session, request, response) 및 스프링 빈 조회 (0) | 2021.09.11 |