목차
인덱스 페이지 만들기
<!DOCTYPE HTML>
<html>
<head>
<title>static content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<a>hello</a>
</body>
</html>
Resources > static > index.html 추가
thymeleaf 템플릿 엔진 동작
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "hello";
}
}
// Java > controller > HelloController.java
<!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>
// resources > templates > hello.html

model의 <data, hello!!>가 hello.html에서 반환되는 것을 확인할 수 있다.
CMD창으로 실행해보기
gradlew.bat 실행 | build>libs 이동 |
|---|
java -jar 실행 | 8080/hello 화면 |
|---|