스프링 부트에 대해 찾고 싶은 내용이 있을 때는 공식 문서 찾아보기
Spring Boot Reference Documentation

요즘은 maven보다는 gradle을 사용하는 추세이니 gradle로 project를 설정하자!
SNAPSHOT, M1는 베타 버전 등 공식적으로 나오지 않은 버전들을 의미한다.

오라클과 자바 라이센스 문제로 모든
javax패키지를jakarta로 변경해줘야 한다.





spring-boot-starter-thymeleaf, spring-boot-starter-web 밖에 없는데 External Library에는 수많은 관련 Library들이 설치되어 있는 것을 확인해볼 수 있다.
spring-boot-starter-thymeleaf, spring-boot-starter-web과 의존 관계가 있는 Library들이며 core, tomcat 등이 있는 것을 확인해볼 수 있다.
dependencies들이 설치되어있는 것을 확인할 수 있다
static 폴더에 index.html 파일을 만들고 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>
Hello World!!
</body>
</html>
java 패키지의 하위 패키지에 controller 패키지를 생성하고 HelloController.java 파일 생성
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
@Controller
public class HelloController {
//hello라는 이름의 Get으로 Mapping
@GetMapping("hello")
public String Hello(Model model){
//data라는 이름으로 Hello World!!! 저장 Map의 key, value같은 느낌
model.addAttribute("data", "Hello World!!!");
//hello.html 파일을 찾아 랜더링
return "hello";
}
}
resources - templetes 패키지에 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>
<!--model에서 key 값이 data인 value를 찾아 대입-->
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
</body>
</html>
실행 후 localhost:8080/hello로 접속

터미널 실행하여 프로젝트 디렉토리로 이동

./gradlew build 입력 후 build - libs 디렉토리로 이동

java -jar jar파일의 이름을 입력하여 실행하여 준다.

실행 확인

스프링 부트에 대해 찾고 싶은 내용이 있을 때는 공식 문서 찾아보기
Spring Boot Reference Documentation