maven/gradle - 버전 설정하고 필요한 라이브러리를 가져오고 관리하는 tool
Gradle은 의존관계가 있는 라이브러리를 함께 다운로드 한다.
(요즘은 Gradle을 사용하는 추세)
Group : 기업의 도메인명
Artifact : 빌드된 결과물 (프로젝트명)
(Dependencies에서 Thymeleaf는 html을 만들어주는 라이브러리)
IntelliJ에서 C:\Users\USER\Study\hello-spring\hello-spring\build.gradle로 프로젝트 열기
repositories{} - 라이브러리들을 다운받는 사이트를 지정
Gradle 대신 자바로 바로 실행시켜 속도 향상시키기
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
// "/hello" 도메인에 들어가면 hello 메소드를 실행시킴.
// model은 MVC에서 그 Model
@GetMapping("hello")
public String hello(Model model) {
// hello.html에 data를 넘김.
model.addAttribute("data", "hello!!");
return "hello"; // hello.html
}
}
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>
(실행이 잘 안된다면 2번을 gradlew.bat clean build로 실행)