김영한 님의 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 강의를 보고 작성한 내용입니다.
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EC%9E%85%EB%AC%B8-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8/dashboard
gradle과 maven 같은 buile tool은 의존관계를 관리해준다
Gradle은 의존관계가 있는 라이브러리를 함께 다운로드
ex> spring-boot-starter-web 라이브러리를 가져오면 tomcat, web과 같이 의존관계가 있는 라이브러리들을 자동으로 가져온다
spring-boot-starter-web
spring-boot-starter-tomcat: 톰캣 (웹서버)
spring-webmvc: 스프링 웹 MVC
spring-boot-starter-thymeleaf: 타임리프 템플릿 엔진(View)
spring-boot-starter : springboot와 관련된 프로젝트를 사용하면 의존관계로 자동으로 import
spring-core
spring-boot-dependencies
spring-boot-autoconfigure
spring-boot-starter-logging ( log 파일 관리를 위해 사용 )
logback ( 요즘에 많이 사용 )
slf4j ( 인터페이스 )
spring-boot-starter-test
junit: 테스트 프레임워크 (JUnit5)
mockito: 목 라이브러리
assertj: 테스트 코드를 좀 더 편하게 작성하게 도와주는 라이브러리
spring-test: 스프링과 통합해서 테스트 지원하는 라이브러리
resources/static
에 index.html을 생성 (정적페이지)
템플릿 엔진 사용가능 ( 동적 페이지 )
FreeMarker
Groovy
Thymeleaf
Mustache
url에 매칭된 Controller의 메소드를 실행
메소드는 model을 생성하고 html 파일의 이름을 return
html의 위치는 resuources/templates
model을 해당 html 파일에 넘긴다
viewResolver
가 resuources/templates
에서 return값에 해당하는 파일명을 찾아서 처리
< HelloController >
@Controller
public class HelloController {
@GetMapping("hello")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "hello";
}
}
< 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>