Spring Boot - Welcome Page ๋ง๋ค๊ธฐ
ํ๋ก์ ํธ ์ ํ ๋ฐฉ๋ฒ : https://jin2rang.tistory.com/entry/Spring-Boot-%EC%85%8B%ED%8C%85%ED%95%98%EA%B8%B0-startspringio ํ๋ก์ ํธ ๊ธฐ์ด์ ์ธ ์ ํ ์ ์๋ฃํ ๋ค View์ Welcome Page๋ฅผ ๋์๋ณด๋ ค๊ณ ํ๋ค. ํ๋ก..
jin2rang.tistory.com
Thymeleaf
Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati
www.thymeleaf.org

Controller์์ ๋ฐ์ดํฐ๋ฅผ ์ ๋ฌํ๊ธฐ ์ํด Controllerํจํค์ง๋ฅผ ์์ฑํ๊ณ , Controllerํ์ผ์ ์์ฑํ๋ค.
package com.jin2rang.hello.controller;
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) {
model.addAttribute("data", " Here's jin2rang blog !!");
return "hello";
}
}
@GetMapping์๋ฏธ๋ HTTP๋ฉ์๋ ์ค GET์ผ๋ก ์์ฒญํ๋ ๊ฒ์ ์๋ฏธํ๊ณ , URL์์ฒญํ ๋ ์ปจํธ๋กค๋ฌ์ ๋ฉ์๋์ ๋งตํํ ๋ ์ฌ์ฉํ๋ค.
@GetMapping("hello")๋ผ๊ณ ์์ฑํ๋ฉด /hello๋ผ๊ณ ์์ฒญํ์ ๋ public String hello(Model model) {...} ์ด ๋ถ๋ถ์ด ๋์ํ๋ค.
ํ์ฌ ์ด ์๋ฒ๋ localhost:8080์ผ๋ก ์คํ๋๊ธฐ ๋๋ฌธ์ localhost:8080/hello๋ผ๊ณ ์์ฒญํ๋ฉด ํด๋น ๊ฒฐ๊ณผ๋ฅผ ํ์ธ ํ ์ ์๋ค.
templatesํด๋์๋ hello.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>
<p th:text="'์๋
ํ์ธ์. ' + ${data}">๋ฐ๊ฐ์ต๋๋ค. Welcome!!</p>
</body>
</html>
๋ง์ง๋ง์ผ๋ก, ์์ Controller ์์ค๋ฅผ ๋ณด๋ฉด return๊ฐ์ด "hello"์ด๋ค.
returnํ๋ hello๋ templatesํด๋์ ์์ฑํ๋ hello.html์ ์ด๋ฆ์ด๋ค.
(resources/templates/hello.html์ hello์ด๋ฆ์ ์๋ฏธํ๋ค.)

์น ๋ธ๋ผ์ฐ์ ์์ ๋ค์๊ณผ ๊ฐ์ด ํ์ธํ๋ค!!
๋ฐฉ๊ธ ์ค์ตํด๋ณธ ๊ฒ์ ์ ๋ฆฌํด๋ณด๋ฉด, ๋์๊ตฌ์กฐ๋ ๋ค์๊ณผ ๊ฐ๋ค.

์ถ์ฒ : ์ธํ๋ฐ - ์คํ๋ง ์ ๋ฌธ - ์ฝ๋๋ก ๋ฐฐ์ฐ๋ ์คํ๋ง ๋ถํธ, ์น MVC, DB ์ ๊ทผ ๊ธฐ์ ๊ฐ์๋ ธํธ
1. localhost:8080/hello๋ก ์์ฒญ
2. helloController์์ @GetMapping("hello")์ด๋ ธํ ์ด์ ์ด ์๋ ๋ฉ์๋์ ๋งตํ๋์ด model์ data๋ผ๋ key์ ๊ฐ์ ๋ฃ์ด hello์ return์ ํ๋ค.
3.Spring Boot๋ด๋ถ์ viewResolver๊ฐ resource/templatesํด๋์์ ํ๋ฉด์ ์ฐพ์์ ์ฒ๋ฆฌํ๋ค.
Spring Boot ํ
ํ๋ฆฟ ์์ง์ ๊ธฐ๋ณธ์ ์ผ๋ก viewName์ ๋งตํํ์ฌ resources:templates/+{ViewName}+.html์ ๊ฐ์ด ๋์ํ๋ค. ๊ทธ๋์ hello๋ฅผ returnํ์ ๋ ํ์ผ์ ์ฐพ์ ํ๋ฉด์ ๊ทธ๋ ค์ฃผ๋ ๊ฒ์ด๋ค.
4. ์น ๋ธ๋ผ์ฐ์ ์์ ํ์ธ!

๊ฒฐ๋ก
1) ํํ๋ฉด์ localhost๋ฅผ ์น๋ฉด index.html๊ณผ ์๋ ๋งคํ๋๋ค
2) ๋๋จธ์ง template ์์ ์๋ htmlํํ์ด์ง๋ค์ Controller์์
@GetMapping("hello")
return "hello"์ ๊ฐ์ ๋ฐฉ์์ผ๋ก ๋ถ๋ฌ์จ๋ค
reference : https://jin2rang.tistory.com/entry/Spring-Boot-thymeleaf-%ED%85%9C%ED%94%8C%EB%A6%BF-%EC%97%94%EC%A7%84