🙂강의🙂
[무료] 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술 - 인프런 | 강의
스프링 입문자가 예제를 만들어가면서 스프링 웹 애플리케이션 개발 전반을 빠르게 학습할 수 있습니다., 스프링 학습 첫 길잡이! 개발 공부의 길을 잃지 않도록 도와드립니다. 📣 확인해주세
www.inflearn.com
▧ 목차 ▧
- Welcome Page 만들기
- Thymeleaf 템플릿 엔진
[ Welcome Page 만들기 ]
✅ src - resources - static - index.html 생성
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
✅ 웹 브라우저 접속 ( http://localhost:8080 )
- https://spring.io/ 접속해서 작동 방식 살펴보기
- Projects - Spring Boot - Learn - Spring Boot Features - 7. Developing Web Applications - 7.1.6 Welcome Page
[ Thymeleaf 템플릿 엔진 ]
- Thymeleaf 공식 사이트 : https://www.thymeleaf.org/
Thymeleaf
Integrations galore Eclipse, IntelliJ IDEA, Spring, Play, even the up-and-coming Model-View-Controller API for Java EE 8. Write Thymeleaf in your favourite tools, using your favourite web-development framework. Check out our Ecosystem to see more integrati
www.thymeleaf.org
- Spring 공식 튜토리얼 : https://spring.io/guides/gs/serving-web-content/
Getting Started | Serving Web Content with Spring MVC
Static resources, including HTML and JavaScript and CSS, can be served from your Spring Boot application by dropping them into the right place in the source code. By default, Spring Boot serves static content from resources in the classpath at /static (or
spring.io
- Spring Boot 메뉴얼 : https://docs.spring.io/spring-boot/docs/2.3.1.RELEASE/reference/html/spring-boot-features.html#boot-features-spring-mvc-template-engines
Spring Boot Features
Graceful shutdown is supported with all four embedded web servers (Jetty, Reactor Netty, Tomcat, and Undertow) and with both reactive and Servlet-based web applications. It occurs as part of closing the application context and is performed in the earliest
docs.spring.io
1. Controller 생성
- src/main/java/hello.hellospring 에 controller package 생성
- controller package 밑에 HelloController 클래스 생성
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) {
// key: data , value: hello!!
// hello.html 에서 ${data} 호출 시 hello!! 반환
model.addAttribute("data", "hello!!");
// return 값은 src/resources/templates 내 html 의 이름과 같아야 함 : rendering
return "hello";
}
}
2. src/resources/templates 에 hello.html 생성
<!DOCTYPE html>
<!-- thymeleaf 문법 사용 가능 -->
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
<!-- key 값이 data 인 value 반환 : hello!! (HelloController 에서 정의) -->
<p th:text="'안녕하세요. ' + ${data}">안녕하세요. 손님</p>
</body>
</html>
3. 웹 브라우저 확인
- GetMapping
- 웹에서 HTML 확인
- 동작 확인
→ Controller 에서 return 값으로 문자 반환 시 viewResolver 가 화면을 찾아 처리
- 스프링 부트 템플릿 엔진 기본 viewName 매핑
- resources:templates/ + {ViewName} + .html
'Spring > 스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술' 카테고리의 다른 글
[ 스프링 웹 개발 기초 ] MVC 와 템플릿 엔진 (0) | 2023.09.07 |
---|---|
[ 스프링 웹 개발 기초 ] 정적 컨텐츠 (0) | 2023.09.07 |
[ 프로젝트 환경설정 ] 빌드하고 실행하기 (0) | 2023.09.06 |
[ 프로젝트 환경설정 ] 라이브러리 살펴보기 (0) | 2023.09.04 |
[ 프로젝트 환경설정 ] 프로젝트 생성하기 (0) | 2023.09.01 |