스프링 웹 개발은 크게 3가지 방법이 있다.
① 정적 컨텐츠
② MVC와 템플릿 엔진
③ API
🌸 정적 컨텐츠
- 파일을 "그대로" 내려줌
- 기본적으로 static 폴더에서 찾아서 내려줌
- 참고 문서
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
🌸 MVC와 템플릿 엔진
- 가장 많이 사용하는 방법
- html을 동적으로 서버에서 변형시킴
- 뷰 리졸버가 동작함
- 컨트롤러에서 리턴값으로 문자를 반환하면 뷰 리졸버가 화면을 찾아서 처리
- 스프링부트 템플릿엔진 기본 viewName 매핑: resources: templates/ + {viewName} + .html
🌸 API
- JSON 같은 데이터 구조 포맷을 내려줌
- 서버끼리 통신할 때 주로 사용
- @ResponseBody를 사용하면 뷰 리졸버를 사용하지 않음
- 뷰 리졸버 대신 HttpMessageConverter가 동작
- HTTP의 Body부분에 데이터를 직접 반환
- @ResponseBody를 사용하고, 객체를 반환하면 객체가 JSON으로 변환됨
이 글은 인프런 [스프링 입문 - 코드로 배우는 스프링 부트, 웹 MVC, DB 접근 기술] 강의를 들으며 학습한 내용을 토대로 작성되었습니다.
'WEB > Spring' 카테고리의 다른 글
[Spring] 스프링 부트에서 caffeine 캐시 사용하기 (0) | 2023.06.13 |
---|---|
[Spring] Spring boot 에서 application.yml 과 application.properties의 차이점 (0) | 2023.05.23 |
[Spring] 빈 생명주기 콜백 (0) | 2023.01.04 |
[Spring] AOP(Aspect Oriented Programming) (1) | 2022.12.29 |
[Spring] 스프링 빈(Spring Bean), 스프링 빈 등록법 (0) | 2022.12.29 |
댓글