Thymeleaf ํ ํ๋ฆฟ ์์ง
ํ์๋ฆฌํ๋ ๋ํ์ ์ธ ๋ทฐ ํ ํ๋ฆฟ ์์ง์ด๋ค.
package jpabook.jpashop;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model){
//data๋ผ๋ ์ด๋ฆ์ ๊ฐ์ง hello!!๋ผ๋ ๋ฐ์ดํฐ๋ฅผ ๋ชจ๋ธ์ ๋ด๋๋ค.
model.addAttribute("data", "hello!!");
// ํ๋ฉด ์ด๋ฆ
return "hello";
}
}
<!DOCTYPE HTML>
<html xmlns:th="<http://www.thymeleaf.org>">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'ใ
ใ
. ' + ${data}" >์๋
ํ์ธ์. ์๋</p>
</body>
</html>
์์น: resource/template/hello.html
indexํ์ด์ง ๋ง๋ค๊ธฐ : static/index.html
<!DOCTYPE HTML>
<html xmlns:th="<http://www.thymeleaf.org>">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
์ฐธ๊ณ : spring-boot-devtools ๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ฉด html ํ์ผ์ ์ปดํ์ผ๋ง ํด์ฃผ๋ฉด ์๋ฒ ์ฌ์์ ์์ด Viewํ์ผ ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํ๋ค. ๋จ์ถํค : Ctrl + Shift + F9(ํ์ฌ ํ์ผ๋ง ๋ฆฌ์ปดํ์ผ)
build.gradle์ ์์กด์ฑ ์ถ๊ฐ
developmentOnly 'org.springframework.boot:spring-boot-devtools'
application.properties์ ์ฌ์ฉ ์ฌ๋ถ ์ถ๊ฐ
spring.devtools.livereload.enabled=true
spring.devtools.restart.enabled=true