> 이전글 읽기 :
2022.02.10 - [:: System Log] - 스프링 입문 강의 노트 #2. 라이브러리 살펴보기
스프링 입문 강의 노트 #2. 라이브러리 살펴보기
2022.02.09 - [:: System Log] - 스프링 입문 강의 노트 #1. 프로젝트 생성 스프링 입문 강의 노트 #1. 프로젝트 생성 스프링 부트 경험이 없어 입문 강의를 간단하게 들어보며 내용을 정리해보려고 한다.
everythingiok.tistory.com
1. View 환경설정
Welcome Page 만들기 - resources/static/index.html
<!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>
> 결과 확인
2. 스프링 부트가 제공하는 Welcome Page 기능
- static/index.html 을 올려두면 Welcome page 기능을 제공한다
- Welcome Page 메뉴얼 페이지 : https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-welcome-page
- thymeleaf 템플릿 엔진
- 스프링 공식 튜토리얼 : https://spring.io/guides/gs/serving-web-content/
- 스프링부트 메뉴얼 : https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-template-engines
> 컨트롤러 기능 추가
1) hello.hellospring 하위 controller 패키지 생성
2) 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";
}
}
3) 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>
<p th:text="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p>
</body>
</html>
> 결과확인
localhost:8080/hello
> 동작 환경 그림
컨트롤러에서 리턴 값으로 문자를 반환하면 뷰 리졸버 ( viewResolver )가 화면을 찾아서 처리한다
- 스프링부트 템플릿엔진 기본 viewName 매핑
- resources/templates/ + (ViewName) + .html
> 다음글 읽기 :
2022.02.16 - [:: System Log] - 스프링 입문 강의 노트 #4. 빌드하고 실행하기
스프링 입문 강의 노트 #4. 빌드하고 실행하기
> 이전글 보기 : 2022.02.10 - [:: System Log] - 스프링 입문 강의 노트 #3. View 환경설정 스프링 입문 강의 노트 #3. View 환경설정 2022.02.10 - [:: System Log] - 스프링 입문 강의 노트 #2. 라이브러리 살..
everythingiok.tistory.com
':: System Log' 카테고리의 다른 글
스프링 입문 강의 노트 #4. 빌드하고 실행하기 (1) | 2022.02.16 |
---|---|
[MSA] 도메인 주도로 설계하는 마이크로서비스 개발 - 3장 (1) (0) | 2022.02.14 |
스프링 입문 강의 노트 #2. 라이브러리 살펴보기 (0) | 2022.02.10 |
스프링 입문 강의 노트 #1. 프로젝트 생성 (0) | 2022.02.09 |
[MSA] 도메인 주도로 설계하는 마이크로서비스 개발 - 2장 (0) | 2022.01.14 |