Welcome Page 만들기
<!DOCTYPE HTML>
<html>
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
스프링부트가 제공하는 기본 Welcom Page 기능
thymeleaf 템플릿 엔진
thymeleaf 공식 사이트: https://www.thymeleaf.org/
스프링 공식 튜토리얼: https://spring.io/guides/gs/serving-web-content/
스프링부트 메뉴얼: https://docs.spring.io/spring-boot/docs/2.7.7/
Controller 동작 확인
HelloController.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";
}
}
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>
동작 환경 그림
- 컨트롤러에서 리턴 값으로 문자를 반환하면 viewResolver 가 화면을 찾아서 처리한다.
- 스프링 부트 템플릿 엔진 기본 view Name 매핑
- resources:templates/ + {ViewName} + .html
(devtools 라이브러리 추가 하면 html 파일을 컴파일만 해주면 서버 재시작 없이 view 파일 변경 가능)
'스프링 > 스프링 입문 - 김영한' 카테고리의 다른 글
5. 스프링 웹 개발 기초 ( MVC와 템플릿 엔진 ) (0) | 2023.01.01 |
---|---|
4. 스프링 웹 개발 기초 ( 정적 컨텐츠 ) (0) | 2023.01.01 |
Gradle 프로젝트에서 IntelliJ 인텔리제이 Spring Boot DevTools 적용하기 (0) | 2023.01.01 |
2. 라이브러리 간단한 설명 (0) | 2022.12.31 |
1. 프로젝트 생성 및 IntelliJ 설정 (0) | 2022.12.31 |