MapleStory Finger Point

๐ŸŸค JAVA/๐ŸŸค Spring

[SpringBoot] thymeleaf ํƒ€์ž„๋ฆฌํ”„ - ํƒ€์ž…/์ œ์–ด๋ฌธ

HYEJU01 2024. 8. 26. 22:28
    <h3>ํƒ€์ž„๋ฆฌํ”„ ๋ณ€์ˆ˜, ์ œ์–ด๋ฌธ</h3>

    <p th:text="${'hello world'}"></p>
    <p>[[${'hello world'}]]</p>

    <p th:text="${1 == 1}"></p>
    <p>[[${1 == 1}]]</p>


    <p th:text="${1 eq 1}"></p>
    <p>[[${1 eq 1}]]</p>

    <h3>๋ณ€์ˆ˜ ์„ ์–ธ</h3>
    <div th:with="a = 10, b = 20">
        [[${a}]]
        [[${b}]]
    </div>

    <h3>์กฐ๊ฑด๋ฌธ</h3>
    <div th:with="a = 10">
        <span th:if="${a == 10}">10๊ณผ ๊ฐ™์Œ</span>
        <span th:if="${a != 10}">10๊ณผ ๊ฐ™์ง€ ์•Š๋‹ค</span>
    </div>


    <div th:with="a = 10">
        <span th:if="${a != 10}">if</span>
        <span th:unless="${a != 10}">if์™€ ์กฐ๊ฑด์„ ๋™์ผํ•˜๊ฒŒ ๋‹ฌ์•„์ค๋‹ˆ๋‹ค (else๋ฌธ)</span>
    </div>


    <h3>3ํ•ญ ์—ฐ์‚ฐ์ž</h3>
    [[${ true ? '์ฐธ์ž…๋‹ˆ๋‹ค' : '๊ฑฐ์ง“์ž…๋‹ˆ๋‹ค'}]]

 

 


 

 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <h3>๋ฐ˜๋ณต๋ฌธ</h3>
    <!--[[${list}]]-->
    <ul>
        <li th:each="vo : ${list}">
            [[${vo.num}]]
            [[${vo.name}]]
            [[${vo.addr}]]
            [[${vo.age}]]
        </li>
    </ul>

    <h3>๋ฐ˜๋ณต๋ฌธ๊ณผ state๊ฐ์ฒด</h3>

    <ul>
        <li th:each="a, state : ${list}">
            [[${state}]]<br>
            [[${state.index}]]<br>
            [[${state.count}]]<br>
            [[${state.size}]]<br>
        </li>
    </ul>

    <h3>list์˜ vo์˜ num๊ฐ€ ์ง์ˆ˜์ธ ๊ฒฝ์šฐ๋งŒ ์ถœ๋ ฅ?</h3>

    <ul>
        <li th:each="a : ${list}" th:if="${a.num % 2 == 0}">
            [[${a.num}]]
            [[${a.name}]]
        </li>
    </ul>


</body>
</html>


 

<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

    <h3>block๊ตฌ๋ฌธ</h3>
    <!-- ํƒ€์ž„๋ฆฌํ”„์—์„œ ํŠน๋ณ„ํ•œ ํƒœ๊ทธ๋ฅผ ์“ฐ์ง€์•Š๊ณ  ๋งˆ์น˜ ์ค‘๊ด„ํ˜ธ ์ฒ˜๋Ÿผ ์‚ฌ์šฉํ•˜๊ณ  ์‹ถ์œผ๋ฉด ์“ธ์ˆ˜ ์žˆ๋Š” ๊ตฌ๋ฌธ-->

    <ul>
        <th:block th:each="vo : ${list}">
        <li>[[${vo}]]</li>
        </th:block>
    </ul>


    <h3>aํƒœ๊ทธ ์‚ฌ์šฉํ•˜๊ธฐ</h3>
    <ul>
        <li th:each="vo : ${list}">
            <!--<a href="ex03_result?num=${vo.num}">[[${vo.name}]]</a>-->
            ๋ฐฉ๋ฒ•1
            <a th:href="@{ex03_result(num=${vo.num}, name=${vo.name}) }">[[${vo.name}]]</a>
            <br>

            ๋ฐฉ๋ฒ•2 (pathVariable - URL์„ ์ฃผ์†Œ๋ฅผ ๊ฐ€๋ณ€๋งค๊ฐœ๋ณ€์ˆ˜๋กœ ์“ฐ๋Š” ๋ฐฉ๋ฒ•)
            <!--<a href="๊ฒฝ๋กœ/๊ฐ’/๊ฐ’">[[${vo.name}]]</a>-->
            <a th:href="@{ex03_result2/{name}/{age}(name=${vo.name}, age=${vo.age}) }">[[${vo.name}]]</a>
        </li>
    </ul>




</body>
</html>