view 환경설정

welcome Page 만들기

<-resources/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>

thymeleaf 템플릿 엔진

@Controller
public class HelloController {
    @GetMapping("hello")
public String hello(Model model) { 
        model.addAttribute("data", "hello!!");
return "hello";
    } 
}
<-resources/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}" >안녕하세요. 손님</p>
</body>
</html>

thymeleaf 템플릿엔진 동작 확인

Untitled

참고: spring-boot-devtools 라이브러리를 추가하면, html 파일을 컴파일만 해주면 서버 재시작 없이 View 파일 변경이 가능하다. 인텔리J 컴파일 방법: 메뉴 build Recompile