타임리프는 html 마크업을 그대로 사용해서 템플릿을 만드는 장점이 있다.
웹 브라우저에서도 열린다.
스프링에서 밀어 준다.
단점은 매뉴얼을 좀 봐야 한다.
보통 spring.io의 guide메뉴를 가보면 아주 좋은 가이드 들이 많다.
스프링 부트를 사용하면 세팅 할 것이 없다.
@Controller
public class HelloController {
@GetMapping("/hello")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "hello";
}
}
resources/templates 폴더에서 hello.html을 찾는다.
<!DOCTYPE html>
<html lang="ko" xmlns:th="<http://thymeleaf.org>">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<h1 th:text="'안녕하세요.' + ${data}">안녕하세요. 손님</h1>
</body>
</html>
정적 컨텐츠는 /resources/static/ 에 넣으면 된다.
템플릿 수정할 때마다 서버 재시작이 너무 귀찮을 때 라이브러리 설치