๋๋น๋
๋์ [Spring ํ๋ก์ ํธ] Spring Boot์์ ํ์๋ฆฌํ(Thymeleaf) ์ฌ์ฉํ๊ธฐ
๊ธ์์ ์บก์ณํ ๊ฒ์
๋๋ค.์ง์๊ณผ ๊ฟํ์ด ๋์น๋ "๋๋น์ ๋ธ๋ก๊ทธ" ๋ฐฉ๋ฌธํ๊ธฐ
"[Spring ํ๋ก์ ํธ] Spring Boot์์ ํ์๋ฆฌํ(Thymeleaf) ์ฌ์ฉํ๊ธฐ" ๊ธ ๋ณด๋ฌ๊ฐ๊ธฐ
th:replace
์ค๋ช
์ ๋ชจ๋ MHLab
๋์ Thymeleaf์์ ํ
ํ๋ฆฟ ํ์์ผ๋ก ์ฌ์ฉํ๊ธฐ(With thymeleaf-layout-dialect)
๊ธ์์ ๊ฐ์ ธ์จ ๊ฒ์
๋๋ค.์ง์๊ณผ ๊ฟํ์ด ๋์น๋ "MHLab์ ๊ฐ๋ฐ ๋ธ๋ก๊ทธ" ๋ฐฉ๋ฌธํ๊ธฐ
Thymeleaf Simple expressions
Variable Expressions: ${...}
Selection Variable Expressions: *{...}
Message Expressions: #{...}
Link URL Expressions: @{...}
th:replace
th:replace
์์ฑ์ ํตํด ๊ฐ ๋ถ๋ถ์ ๋ํ ๊ณตํต ๋ ์ด์์์ ์ฌ์ ์- ํด๋น ์์ฑ์ด ์ ์ธ๋
html
ํ๊ทธ๋ฅผreplace
์ ์ ์๋ ๋ค๋ฅธhtml
ํ์ผ๋ก ์นํํ๋ ๊ฒ์ผ๋กjsp
์include
์ ๋น์ทํ ๋์์ ํํฉ๋๋ค.th:replace
์์ฑ์ ๊ฒฝ๋ก๋Spring-boot
์ ๊ธฐ๋ณธ ๊ฒฝ๋ก์ธtemplates
ํ์์ ์ ์ํ ๊ฒฝ๋ก๋ฅผ ์์ฑ ํ::
๋ค์๋ ์๋์์ ์๊ฐํfragment
์์ฑ์ ์ด๋ฆ์ ์ ์ด์ค๋๋ค.th:replace
๋fragment
ํ๊ทธ๋ฅผ ์ ์ธํ๊ณ ๊ฒฐ๊ณผ๋ฅผ ๊ฐ์ ธ์ต๋๋ค.
th:attr
<span id="globalConst"
sec:authorize="isAuthenticated()"
th:with="auth=${#authentication.getPrincipal().getUser()}"
th:attr="data-iuser=${auth.iuser},
data-writer=${auth.nm},
data-writer-profile=${auth.mainProfile}"></span>
th:attr="data-iuser=${auth.iuser}, data-writer=${auth.nm}, data-writer-profile=${auth.mainProfile}"
html
์ ์์data-ooo
์ ๊ฐ์ ์๋ฒ์์ ๋ฐ์model
๊ฐ์ผ๋ก ํ๊ฐ ~ ์ฌ๋ฌ๊ฐ ์ง์ ํ ์ ์๋ค .
th:class
<p th:class="${isAdmin} ? admin-class : user-class ">
Some Text 2
</p>
๐
<p class="admin-class">
Some Text 2
</p>
th:classappend
<p class ="base-class" th:classappend="${isAdmin} ? admin-class : user-class">
Some Text 1
</p>
๐
<p class ="base-class admin-class">
Some Text 1
</p>