반응형
타임리프에서 리터럴을 사용할 때를 보겠습니다.
타임리프에서 리터럴은 아래와 같습니다.
문자 : 'hello', 'world'
숫자 : 10 20 30
boolean : true, false
null : null
문자는 작은 따옴표로 감싸야 하는데 이는 상당히 귀찮습니다. 그래서 띄어쓰기가 없다면 그냥 하나의 토큰으로 보고 작은 따옴표가 아닌 " "로 감싸도 됩니다.
< th:text="hello"> -- O
<th:text="hello world"> -- X
이 경우는 공백이 있기 때문에 작음따옴표로 감싸주어야 합니다.
<th:text=" 'hello world' "> -- O
<!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 ' + ${data} = <span th:text="'hello ' + ${data}"></span></li>
<li>리터럴 대체 |hello ${data}| = <span th:text="|hello ${data}|"></span></li>
</ul>
</body>
</html>
리터럴 대체는 | |로 리터럴을 감싸는 리터럴 대체 문법인데 1,2,3번째 코드보다 훨씬 편리한 것을 볼 수 있습니다.
반응형
'Spring > Spring' 카테고리의 다른 글
[Spring] BindingResult / FieldError / ObjectError (2) | 2024.10.16 |
---|---|
[Spring] 메시지, 국제화 (3) | 2024.10.15 |
[Spring] 타임리프 - 텍스트 (1) | 2024.10.09 |
[Spring] @ResponseBody 애너테이션 (1) | 2024.10.03 |
[Spring] HTTP 요청 파라미터 - 쿼리 파라미터 (1) | 2024.10.03 |