π[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