Notice
Recent Posts
Recent Comments
«   2024/09   »
1 2 3 4 5 6 7
8 9 10 11 12 13 14
15 16 17 18 19 20 21
22 23 24 25 26 27 28
29 30
Archives
Today
Total
관리 메뉴

충분히 쌓여가는

JSP, thymeleaf, text, utext, |(리터럴 치환) 본문

Spring/연습

JSP, thymeleaf, text, utext, |(리터럴 치환)

빌드이너프 2023. 10. 4. 17:11

test.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1 th:text="${lastName}"></h1>
    <h1>[[${firstName}]]</h1>
</body>
</html>

 

Controller

@GetMapping("/test")
public String test(Model model) {
    model.addAttribute("lastName", "enough");
    model.addAttribute("firstName", "build");
    return "test";
}

 


text와 utext

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1 th:text="${lastName}"></h1>
    <h1>[[${firstName}]]</h1>
    <span th:text="${'<i>enough, build</i>'}"></span><br>
    <span th:utext="${'<i>enough, build</i>'}"></span>
</body>
</html>


|(리터럴 치환)

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
    <h1 th:text="${lastName}"></h1>
    <h1>[[${firstName}]]</h1>

    <h1 th:text="'My Name is' + ${lastName} + ', ' + ${firstName}"></h1>
    <h1 th:text="|My Name is ${lastName}, ${firstName}|"></h1>

    <span th:text="${'<i>enough, build</i>'}"></span><br>
    <span th:utext="${'<i>enough, build</i>'}"></span>
</body>
</html>