2022.01.08 - [Spring Boot] - [프로젝트 환경설정] 프로젝트 생성
개발 환경
- 윈도우
- Java SE 11
- IntelliJ
view 환경설정
Welcome Page 생성
스프링 부트는 index.html을 Welcom page 기능으로 제공한다. 아래 위치에 index.html 파일을 생성한다.
- resources/static/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
- 패키지명.controller/HelloController.java
package com.example.hello.hello.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("name", "김철수");
return "hello";
}
}
- resources/templates/hello.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
<meta charset="UTF-8">
<title>Hello</title>
</head>
<body>
<p th:text="'Hello, ' + ${name}" >Hello!</p>
</body>
</html>
thymeleaf 템플릿엔진 동작 확인
http://localhost:8080과 http://localhost:8080/hello를 실행해보면 다음 화면과 같이 나타나는 것을 확인할 수 있다.
실행 원리
빌드
- 명령 프롬프트(cmd) 실행
- 프로젝트가 저장된 경로로 이동
- gradlew.bat build 실행
- cd build/libs
- java -jar 파일명: IntelliJ와 같은 포트를 사용하므로 실행 전에 IntelliJ는 실행 중지
'Spring Boot' 카테고리의 다른 글
[스프링 웹 개발 기초] 정적 콘텐츠 vs MVC와 템플릿 엔진 vs API (0) | 2022.01.10 |
---|---|
[프로젝트 환경설정] 프로젝트 생성 (0) | 2022.01.08 |