ํ์๋ฆฌํ ์ฌ์ฉ๋ฒ

<html xmlns:th="http://www.thymeleaf.org">
th:href="@{/css/bootstrap.min.css}"
ํ์๋ฆฌํ ์ ์ธ์ ํด์ฃผ์ด์ผ ๋น๋ก์ ํ์๋ฆฌํ ๋ฌธ๋ฒ์ ์ดํดํ ์ ์๋ค.
ํ์๋ฆฌํ๋ฅผ ์ฌ์ฉํ๊ฒ ๋๋ฉด,
th:xx ์์ฑ์ด ๋ถ์ ๋ถ๋ถ์ ์๋ฒ์ฌ์ด๋์์ ๋ ๋๋ง ๋๋ฉฐ , ๊ธฐ์กด html ์์ฑ์ด ๋์ฒด๋๋ค.(th ์์ฑ์ด ์์ผ๋ฉด html ๊ทธ๋๋ก ์ฌ์ฉ)
ํ์ง๋ง html ์ ํ์ผ๋ก ์ง์ ์ด์์๋ th ์์ฑ์ ๋ฌด์๋๋ค.
1.URL ๋งํฌ ํํ์
th:onclick="|location.href='@{/basicCafe/items/edit/{cafeId}(cafeId=${cafe.id})}'|"
ํ์๋ฆฌํ๋ url๋งํฌ๋ฅผ @{...}๋ก ํํํ๋ค.
์ด ๊ฒฝ์ฐ ์๋ธ๋ฆฟ ์ปจํ ์คํธ๋ฅผ ์๋์ผ๋ก ํฌํจํ๋ค.
2.๋ฆฌํฐ๋ด ๋์ฒด ๋ฌธ๋ฒ
location.href='/basic/items/add'
th:onclick="'location.href=' + '\'' + @{/basic/items/add} + '\''"
th:onclick="|location.href='@{/basic/items/add}'|"
๋ฆฌํฐ๋ด ๋์ฒด ๋ฌธ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ณต์กํ ํํ์์ ๊ฐ๊ฒฐํ๊ฒ ํํํ ์ ์๋ค.
3.๋ฐ๋ณต์ถ๋ ฅ
์ฌ์ฉ์์
<tr th:each="item : ${items}">
<tr th:each="cafe:${cafes}">
<td><a href="cafe.html" th:href="@{/basicCafe/items/{itemId}(itemId=${cafe.id})}" th:text="${cafe.id}">1</a></td>
<td><a href="cafe.html" th:href="@{|/basicCafe/items/${cafe.id}|}" th:text="${cafe.cafeName}">ํ
์คํธ ์ํ1</a></td>
<td th:text="${cafe.open}">10000</td>
<td th:text="${cafe.close}">10</td>
<td th:text="${cafe.mocaPrice}">10</td>
</tr>
์ปฌ๋ ์ ์ ์๋ง์ <tr>,</tr> ํ์ ํ๊ทธ๋ค์ ํฌํจํด์ ์์ฑ๋๋ค.
4.๋ณ์ ํํ์
th:text="${cafe.id}">1</a></td>
๋ด์ฉ์ ๊ฐ์ th:text ๊ฐ์ผ๋ก ๋ณ๊ฒฝํด์ค๋ค.
5.๋งํฌ ํํ์
th:href="@{/basic/items/{itemId}(itemId=${item.id})}
th:href="@{|/basic/items/${item.id}|}"
๋ฆฌํฐ๋ด ๋์ฒด ๋ฌธ๋ฒ์ ์ฌ์ฉํ๋ฉด ๋ณต์กํ ๋งํฌ ํํ์์ ๊ฐ๊ฒฐํ๊ฒ ํํํ ์ ์๋ค.
"์์ HTML์ ๊ทธ๋๋ก ์ ์งํ๋ฉด์ ๋ทฐ ํ ํ๋ฆฟ๋ ์ฌ์ฉํ ์ ์๋ ํ์๋ฆฌํ์ ํน์ง์ ๋ค์ธ๋ด ํ ํ๋ฆฟ์ด๋ผ ํ๋ค."
'mvc ์น ๊ฐ๋ฐ' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
ํ๋ก ํธ ์ปจํธ๋กค๋ฌ (0) | 2022.02.08 |
---|