Gradle?
Maven?
Version
SNAPSHOT 과 M1은 아직 정식 출시전의 버전이니 참고
Group
Artifact
Name
프로젝트 명을 의미한다.
Dependencies
어떤 라이브러리를 사용 할 것 인지?
Spring Web, Thymeleaf
설정 후 Generate를 하게 되면 파일이 다운 된다.
다운 된 파일을 압축해제 하고 IntelliJ에서 Open 하면 설정에 필요한 파일들이 다운로드 된다.
java파일을 실행하게 되면 내장되어있는 Tomcat에 의해 웹 서버가 실행 된다.
** Gradle 설정에서 Build and run using 과 Run tests using 부분을 IntelliJ IDEA 를 사용하면 더 빠르게 켜진다고 한다.
Dependencies에서 선택한 라이브러리들을 설치하게 되는데 두 개만 설치했음에도 불구하고 관련된 라이브러리들이 자동으로 설치되게 된다.
(**양이 생각보다 엄청 많다!)
index.html 코드 내용
<!DOCTYPE HTML>
<html>
<head>
<title>Hello Spring Boot</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
Hello World
<a href = "/hello">hello</a>
</body>
</html>
스프링 공식 튜토리얼 : https://spring.io/guides/gs/serving-web-content/
스프링 부트 메뉴얼 : https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#web.servlet.spring-mvc.template-engines
thymeleaf 템플릿엔진 동작 확인
html 코드 (main - 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>
Java 코드 (main - java - ...)
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 {
@GetMapping("hello")
public String hello(Model model){
model.addAttribute("data", "hello!!");
return "hello";
}
}
cmd 콘솔로 이동
1. ...\hello-spring\hello-spring 에서 gradlew.bat 실행
2. build\libs 로 이동
3. java - jar.hello-spring~~.jar command로 파일 실행
4. 잘 되지 않는 경우 clean build 사용