충분히 쌓여가는
JSP, thymeleaf, text, utext, |(리터럴 치환) 본문
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>
'Spring > 연습' 카테고리의 다른 글
중복된 URL 코드 제거(@RequestMapping) (0) | 2023.10.03 |
---|---|
@RequestMapping, @GetMapping, @PostMapping (0) | 2023.10.03 |
매개변수 묶어서 사용(@ModelAtrribute) (0) | 2023.10.02 |
컨트롤러 메서드의 반환타입(String, void, ModelAndView) (0) | 2023.10.02 |
thymeleaf 기본 설정 (0) | 2023.10.02 |