1. What is Thymeleaf
Thymeleaf๋ server-side JAVA ๊ธฐ๋ฐ์ template engine ์ด๋ค.
Spring boot ๊ฐ ๊ถ์ฅํ๋ ํ ํ๋ฆฟ ์์ง ์ค ํ๋์ด๋ค.(Groovy, Thymeleaf, FreeMarker..) ๊ทธ๋์ ์ฌ์ฉํด์๋ jsp๋ณด๋ค ๋ ๊ฐ๋จํ ์ค์ ๊ณผ ํ์ค ๋ฌธ๋ฒ์ผ๋ก HTML์ ์์ฑํ ์ ์๋ค. Thymeleaf๋ ์น ํ์ค, ํนํ HTML5 ์ ๋ง์ถฐ ์ค๊ณ๋์๊ธฐ์ ์์ ํ ๊ฒ์ฆ๋ ํ ํ๋ฆฟ์ ๋ง๋ค ์ ์๋ค.
JSP์ ๊ฒฝ์ฐ, tag libraries๋ฅผ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ, HTML ํ์ค ํ๊ทธ๊ฐ ์๋๊ธฐ์ ๋ธ๋ผ์ฐ์ ๊ฐ ํด์ํ ์ ์๋ ์ฝ๋๊ฐ ๋๋ค.
<form:inputText name="userName" value="${user.name}" />
Thymeleaf๋ฅผ ์ด์ฉํ์ฌ ์์ฑํ ๊ฒฝ์ฐ, ๋ธ๋ผ์ฐ์ ๊ฐ ํด์ํ ์ ์๋ ์ฝ๋๊ฐ ๋๋ค. ๋ฌธ๋ฒ ์ญ์ ๊น๋ํ๊ฒ ๋ณด์ธ๋ค.
<input type="text" name="userName" value="James Carrot" th:value="${user.name}" />
์ด๋ก ์ธํด ํผ๋ธ๋ฆฌ์ , ๋์์ธ๊ณผ ๊ฐ๋ฐํ์ ๊ฒฉ์ฐจ๋ฅผ ํด์ํ๋ฉฐ ์ปค๋ฎค๋์ผ์ด์ ์ ๊ฐ์ ํ ์ ์๋ ๊ฒ์ ์ดํํ๋ค.(๊ณต์ doc์์..)
์ด๋ฒ์ ์ฌ์ฉํด๋ณด๋ ๊ฐ๋ฐํ ๋๋ Thymeleaf ๊ฐ ํจ์ฌ ํธํ๋ค. jsp์ ๊ฒฝ์ฐ view ํ ํ๋ฆฟ ๋ ๋๋ง์ Servlet Container๊ฐ ํ๊ธฐ ๋๋ฌธ์ ๊ฒฐ๊ณผ๋ฅผ ๋ณด๋๋ฐ ๋๋ ์ด๊ฐ ์๋ค. ๋ฐ๋ฉด Thymeleaf์ ๊ฒฝ์ฐ๋ Servlet Container ๊ฐ์ ์์ด ์ต์ข View๋ฅผ ์์ฑํ๋ฏ๋ก, ๋ฐ๋ก ํ์ธ์ด ์์ํ๋ค. ํ ์คํธ ์์๋ Servlet Container๋ฅผ ๋์ธ ํ์๊ฐ ์์ผ๋ฏ๋ก mockMVC์ผ๋ก๋ ํ ์คํธ ์ฝ๋ ์์ฑ์ด ๊ฐ๋ฅํ๋ค.
๋ง์ฝ frond-end ๊ฐ๋ฐ์๊ฐ Thymeleaf์์ด view๋ฅผ ๋๋๋งํด์ ๋ง๋ค๊ณ ์๋ค๋ ๊ฒฝ์ฐ๋ผ๋ฉด, ์ด๋ฅผ ๊ณ ๋ คํ์ฌ attribute ๋ ์ถ๊ฐํด์ค์ผ ํ๋ค..
2. Standard Expression Syntax
[Simple expressions]
Variable Expressions: ${...}
Selection Variable Expressions: *{...}
Message Expressions: #{...}
Link URL Expressions: @{...}
Fragment Expressions: ~{...}
[Text operations]
String concatenation: +
Literal substitutions: |The name is ${name}|
3. Thymeleaf Doc
Tutorial: Using Thymeleaf
1 Introducing Thymeleaf 1.1 What is Thymeleaf? Thymeleaf is a modern server-side Java template engine for both web and standalone environments, capable of processing HTML, XML, JavaScript, CSS and even plain text. The main goal of Thymeleaf is to provide a
www.thymeleaf.org
'SRPING' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
์์กด์ฑ ์ฃผ์ (Dependency Injection) ์ข ๋ฅ /@RequiredArgsConstructor (1) | 2023.01.30 |
---|---|
JPA ๊ฐ์ฒด์ ์ํ / @Transactional (0) | 2023.01.30 |
Model Binding : WebDataBinder, @InitBinder (0) | 2023.01.18 |