๐[Spring] Welcome Page ๊ตฌํ ๋ฐ ๋์ ๋ฐฉ๋ฒ.
1๏ธโฃ Welcom Page ๋ง๋ค๊ธฐ.
- Welcom Page๋
'resource/static'
๋ด๋ถ์'index.html'
์ด๋ผ๋ ํ์ผ๋ก ๋ง๋ค๋ฉด ๋ฉ๋๋ค.
```html
<!DOCTYPE html>
- ์คํ๋ง ๋ถํธ๊ฐ ์ ๊ณตํ๋ Welcom Page ๊ธฐ๋ฅ.
- **`'static/index.html'`** ์ ์ฌ๋ ค๋๋ฉด Welcom page ๊ธฐ๋ฅ์ ์ ๊ณตํฉ๋๋ค.
- [Spring.io ๊ณต์ ๋ํ๋จผํธ](https://docs.spring.io/spring-boot/3.3-SNAPSHOT/reference/web/reactive.html#web.reactive.webflux.welcome-page)
## 2๏ธโฃ thymeleaf ํ
ํ๋ฆฟ ์์ง.
- [thymeleaf ๊ณต์ ์ฌ์ดํธ](https://www.thymeleaf.org/)
- [์คํ๋ง ๊ณต์ ํํ ๋ฆฌ์ผ](https://spring.io/guides/gs/serving-web-content)
- [์คํ๋ง๋ถํธ ๋ฉ๋ด์ผ](https://docs.spring.io/spring-boot/3.3-SNAPSHOT/reference/web/servlet.html#web.servlet.spring-mvc.template-engines)
```java
// com/devkobe/hello_spring/controller
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "hello";
}
}
<!-- `resource/static/index.html` -->
<!DOCTYPE html>
<html>
<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>
<!-- `resource/templates/hello.html` -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
</head>
<meta charset="UTF-8">
<body>
<p th:text="'์๋
ํ์ธ์. ' + ${data}" >์๋
ํ์ธ์. ์๋</p>
</body>
</html>
-
thymeleaf ํ
ํ๋ฆฟ์์ง ๋์ ํ์ธ
- ์คํ :
http://localhost:8080/hello
- ์คํ :
-
๋์ ํ๊ฒฝ ๊ทธ๋ฆผ.
- ์ปจํธ๋กค๋ฌ์์ ๋ฆฌํด ๊ฐ์ผ๋ก ๋ฌธ์๋ฅผ ๋ฐํํ๋ฉด ๋ทฐ ๋ฆฌ์กธ๋ฒ(
'viewResolver'
) ๊ฐ ํ๋ฉด์ ์ฐพ์์ ์ฒ๋ฆฌํฉ๋๋ค.- ์คํ๋ง ๋ถํธ ํ
ํ๋ฆฟ์์ง ๊ธฐ๋ณธ
'viewName'
๋งคํ.-
'resources:template/'
+'{ViewName}'
+'.html'
-
- ์คํ๋ง ๋ถํธ ํ
ํ๋ฆฟ์์ง ๊ธฐ๋ณธ
๐โโ๏ธ ์ฐธ๊ณ :
'spring-boot-devtools'
๋ผ์ด๋ธ๋ฌ๋ฆฌ๋ฅผ ์ถ๊ฐํ๋ฉด'html'
ํ์ผ์ ์ปดํ์ผ๋ง ํด์ฃผ๋ฉด ์๋ฒ ์ฌ์์ ์์ด View ํ์ผ ๋ณ๊ฒฝ์ด ๊ฐ๋ฅํฉ๋๋ค.
IntelliJ ์ปดํ์ผ ๋ฐฉ๋ฒ : ๋ฉ๋ด build โ Recompile