스프링 웹 개발 방식에 대해서 공부해보자 !
웹을 개발하는 방법에는 크게 3가지가 있다.
정적 컨텐츠, MVC와 템플릿 엔진, API인데 하나하나 어떤 것인지 알아보자.
1. 정적 컨텐츠
전에 사용했던 방식으로 따로 가공을 거치지 않고 파일을 웹 브라우저에 그대로 내보내는 방식이다.
Spring boot는 정적 컨텐츠 기능을 자동으로 제공한다.
아래 사이트를 들어가서 확인해보면 /static 경로에 있는 static content들을 제공한다는 내용이 있다.
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️⃣ /static 경로에 hello-static.html 을 만들고 아래 내용을 작성해보자
<!DOCTYPE HTML>
<html>
<head>
<title>static content</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
정적 컨텐츠 입니다.
</body>
</html>
2️⃣ localhost:8080/hello-static.html 에 들어가면 아래와 같이 화면을 확인할 수 있다.
🤔 이런 내용으로 알 수 있는 것은 원하는 파일을
resources/static폴더에 넣으면 그대로 반환한다는 것으로 정적컨텐츠이라고 한다.
사진으로 더욱 자세히 서술해보면,
1. l ocalhost:8080/hello-static.html에 대해서 내장 서버인 tomcat에게 요청한다.
2. tomcat이 hello-static.html에 대해서 다시 Spring에게 요청한다.
3. Spring이 hello-static.html 요청을 받으면 Controller에게 요청을 보내고 hello-static.html이 있는지 확인한다.
4. Controller에서 hello-static이 mapping된 메서드를 못찾아 resources/static폴더에 hello-static.html에 파일을 반환한다.
다음시간에는 MVC와 템플릿 엔진을 공부하기로 하자!
'ON > 실습' 카테고리의 다른 글
[Spring Boot] 스프링 웹 개발 기초 ③ - API (2) | 2023.11.06 |
---|---|
[Spring Boot] 스프링 웹 개발 기초 ② - MVC와 템플릿 엔진 (1) | 2023.11.05 |
[Spring Boot] 스프링 부트 프로젝트 생성 | cmd 창으로 빌드 및 실행 ② (0) | 2023.11.03 |
[Spring Boot] 스프링 부트 프로젝트 쉽게 생성하기 ① (0) | 2023.11.02 |
[Spring Boot] 스프링 부트와 스프링의 차이점 (1) | 2023.11.01 |