Gradle은 의존관계가 있는 라이브러리를 함께 다운로드 한다.
ㆍspring-boot-starter-web
ㆍspring-boot-starter-tomcat: 톰캠(웹서버)
ㆍspring-web-mvc: 스프링 웹 MVC
ㆍspring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
ㆍspring-boot-starter(공통): 스프링 부트 + 스프링 코어 + 로깅
ㆍspring-boot
ㆍspring-core
ㆍspring-boot_starter-logging
ㆍlogback, slf4j
ㆍspirng-boot-starater-test
ㆍjunit: 테스트 프레임워크
ㆍmockito: 목 라이브러리
ㆍassertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
ㆍspring-test: 스프링 통합 테스트 지원
resource/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 herf="/hello">hello</a> </body> </html>
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data", "hello!!");
return "hello";
}
}
resource/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 템플릿엔진 동작 확인
ㆍ실행: http://localhost:8080/hello
ㆍ컨트롤러에서 리턴 값으로 문자를 반환하면 뷰 리졸버(viewResolver)가 화면을 찾아서 처린한다.
ㆍ스프링 부트 템플릿엔진 기본 viewName 매핑
ㆍresources:templates/ + {ViewName} + .html
참고자료: 인프런 스프링입문 김영한님 강의노트