
spring-boot-starter-web
spring-boot-starter-thymeleaf : 타임리프 템플릿 엔진(View)
spring-boot-starter(공통) : 스프링 부트 + 스프링 코어 + 로깅


Spring Boot supports both static and templated welcome pages. It first looks for an index.html file in the configured static content locations. If one is not found, it then looks for an index template. If either is found, it is automatically used as the welcome page of the application. spring boot 문서
<!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>
스프링 부트가 제공하는 Welcome Page기능
static/index.html을 올려두면 Welcome page기능을 제공한다Spring MVC supports a variety of templating technologies, including Thymeleaf, FreeMarker, and JSPs
Thymeleaf is a modern server-side Java template engine for both web and standalone environments.
Thymeleaf's main goal is to bring elegant natural templates to your development workflow — HTML that can be correctly displayed in browsers and also work as static prototypes, allowing for stronger collaboration in development teams.
With modules for Spring Framework, a host of integrations with your favourite tools, and the ability to plug in your own functionality, Thymeleaf is ideal for modern-day HTML5 JVM web development. thymeleaf
여러 도구, 플러그인, 스프링 프레임워크 등과 같이 HTML5 JVM 웹개발에 사용하기에 좋은 서버 자바 템플릿 엔진이다
@Controller
public class HelloController {
//GetMapping은 해당 이름과 메소드를 매핑해주는 것
@GetMapping("hello") <-- 웹 애플리케이션에서 슬롯(URL)이 hello라고 들어오면 아래 메소드를 호출해준다
//스프링이 Model형 객체를 만들어서 hello메소드에 넣어서 실행해준다
public String hello(Model model)
{
model.addAttribute("data", "hello!"); <-- 첫번째 인자가 Key, 두번째 인자가 Value로 작동한다, html에서 key값을 넣어서 value값으로 치환하여 출력하는 형태
return "hello"; <-- 해당 반환값을 이용하여 HTML파일을 찾는다
}
}
resources/templates/에서 찾는다resources:templates/+{viewName}+.html<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org"> <head> <!--템플릿 엔진으로 thymeleaf를 사용을 명시-->
<title>Hello</title> <!--브라우저 탭 이름-->
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> </head>
<body>
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p> <!--data가 key로서 불려진 메소드의 model.addAttribute를 통해 들어간 value값을 가져와서 치환된다-->
</body>
</html>
spring-boot-devtools라이브러리를 추가하면,html파일만 컴파일해서 서버 재시작 없이 View파일 변경이 가능하다, build -> Recompile

