1. Welcome Page
- http://localhost:8080/ 요청
- static 폴더에서 index 파일 찾음 ( static/index.html )
- static 폴더에 없으면 templates 폴더에서 index 파일 찾음 ( templates/index.html )
2. thymeleaf 템플릿 엔진
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "hello";
}
}
- http://localhost:8080/hello 요청
- 컨트롤러에서 리턴 값으로 문자를 반환하면 뷰 리졸버( viewResolver )가 화면을 찾아서 처리
( templates/hello.html )
- 스프링 부트 템플릿엔진 기본 viewName 매핑
- resources: templates/ +{ViewName}+ .html
3. 빌드하고 실행하기
- 해당 프로젝트 경로로 이동
- ./gradlew build
- cd build/libs
- java -jar hello-spring-0.0.1-SNAPSHOT.jar
- 실행확인