김영한 선생님의 스프링 입문 강의를 정리한 글
프로젝트 생성하기
사전 준비
Java 11
- 출시 이후 긴 기간동안 보안 업데이트와 버그수정을 지원하는 LTS 버전으로 사용

Eclipse 또는 IntelliJ
스프링 부트 스타터 사이트에서 스프링 프로젝트 생성
프로젝트 설정
Gradle Project
- 라이브러리, 프로젝트, 의존성 관리 도구로 maven 보다 최대 100배 빠름
Dependencies: Spring Web, Thymeleaf
스프링 부트 애플리케이션을 실행하면 자체 내장 서버인 톰켓과 함께 실행됨
라이브러리 살펴보기
스프링 부트 라이브러리
spring-boot-starter-web
- spring-boot-starter-tomcat
- spring-web-mvc
spring-boot-starter-thymeleaf: 템플릿 엔진, html로 변환
spring-boot-starter: 스프링부트+스프링코어+로깅
테스트 라이브러리
spring-boot-starter-test
- junit: 테스트 프레임워크
- mokito: mock 라이브러리
- assertj: 테스트코드 작성을 편하게 도와주는 라이브러리
- spring-test: 스프링 통합 테스트 지원
View 환경설정
Welcome page 경로
- `src/main/resources/static/index.html`
- spring boot welcome page
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
Thymeleaf 템플릿 엔진
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
동작 환경
(웹 브라우저) ➡localhost:8080/intro ➡ (내장 톰캣서버) ➡ (스프링 컨테이너-introController) ➡ return "intro", model(name:spring님) ➡ (스프링 컨테이너-viewResolver) ➡ template/intro.html-thymeleaf 템플릿 엔진 처리 ➡ intro.html ➡ (웹 브라우저)
- controller 에서 리턴 값으로 문자열을 반환하면 viewResover가 화면을 찾아서 반환함
- `resources/templates/{viewName}.html`
정적 컨텐츠
스프링부트에서 기본적으로 정적 콘텐츠를 제공함
resources/static/static.html
<html>
<head>
<title>static content</title>
</head>
<body>
<h1>Hi<h1>
<p>static content page.</p>
</body>
</html>
동작과정

MVC와 템플릿 엔진
MVC: Model, View, Controller
역할에 따라 관심사를 분리한 패턴
- View: 화면을 그리는데 집중
- resources/templates/mvc.html
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Intro</title>
</head>
<body>
<h1 th:text="${input}" is MVC input value.> </h1>
</body>
</html>
- Model, Controller: 데이터와 내부 로직을 처리하는데 집중
@GetMapping("mvc")
public String mvc(@RequestParam("input") String input, Model model) {
model.addAttribute("input", input);
return "mvc";
}
동작과정

'IT' 카테고리의 다른 글
[네트워크] 윈도우 서버 설정 방 (0) | 2022.07.02 |
---|---|
[네트워크] 라우터 설정 명령어 정리 (0) | 2022.07.02 |
[네트워크] OSI 7Layer (0) | 2022.05.03 |
[네트워크] IPv4와 네트워크 클래스 (0) | 2022.04.26 |
[k8s] 쿠버네티스 컨피그맵(Kubernetes ConfigMap) (0) | 2021.05.17 |