🎯 Server에서 Client로 Data를 전달하는 방법
- 정적 리소스, View Template, HTTP Message Body 세 가지 방법 존재
1. 정적 리소스 (Static Resources)

🔧 Spring Boot의 정적 리소스 기본 경로
| 디렉토리 경로 | 설명 |
|---|---|
/static | 가장 자주 사용됨 |
/public | 대체 가능 |
/META-INF/resources | 웹 서버에서 인식 가능한 루트 |
src/main/resources/ | 이 내부에 위 폴더들이 존재해야 함 |
🧪 예시
파일 위치: src/main/resources/static/hello/world.html
접근 URL: http://localhost:8080/hello/world.html
→ 정적 리소스는 컨트롤러를 거치지 않고 바로 응답됨
2. View Template (SSR: 서버사이드 렌더링)

✨ 대표 엔진
📌 Spring Boot 설정 기본값
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
→ HTML 템플릿은 src/main/resources/templates/ 에 위치해야 함
✅ 컨트롤러에서 View 반환
@Controller
public class ViewTemplateController {
@RequestMapping("/response-view")
public String responseView(Model model) {
model.addAttribute("data", "sparta"); // View에 전달할 데이터
return "thymeleaf-view"; // templates/thymeleaf-view.html
}
}
🧾 thymeleaf-view.html
<h2 th:text="${data}"></h2> <!-- 'sparta' 가 출력됨 -->
→ @ResponseBody가 없으면 ViewResolver가 실행되어 .html을 찾아 렌더링함
❗ 주의: @ResponseBody가 있으면?
@Controller
public class ViewController {
@ResponseBody
@RequestMapping("/response-body")
public String responseBody() {
return "thymeleaf-view";
}
}
@RestController와 같은 동작⚠️ 반환 타입이 void인 경우
@Controller
public class ViewTemplateController {
@RequestMapping("/thymeleaf-view")
public void responseViewV2(Model model) {
model.addAttribute("data", "sparta");
}
}
→ View 이름을 명시하지 않으면 요청 URL을 기준으로 View 이름을 유추함
→ 위 예시는 "thymeleaf-view" 템플릿을 찾게 됨
⚠ 실무에서는 혼동을 피하기 위해 명시적 View 이름 반환을 권장
3. HTTP Message Body
응답 데이터를 직접 Message Body에 담아 반환 (JSON, TEXT 등)

주로 API 응답, 모바일 클라이언트 응답 등에서 사용
@ResponseBody, ResponseEntity, @RestController 등 활용
View를 사용하지 않음 → HTML이 아닌 데이터만 전달
📌 응답 방식 요약
| 구분 | 설명 | 사용 예시 |
|---|---|---|
| 정적 리소스 | HTML, CSS, JS, 이미지 등 | 고정된 파일 다운로드 또는 웹 화면 표시 |
| View Template | 서버에서 HTML을 동적으로 생성 | JSP, Thymeleaf 등 |
| HTTP Message Body | JSON, TEXT 등 API 응답 | REST API 응답 (데이터 중심) |
📌 응답 방식 요약 비교표
| 방식 | 목적 | View 사용 | 주요 기술/어노테이션 |
|---|---|---|---|
| 정적 리소스 | 변경 없는 파일 제공 | ❌ | resources/static 등 |
| View Template | HTML 동적 생성 | ⭕ | @Controller, Thymeleaf |
| HTTP Body | JSON 등 데이터 응답 | ❌ | @ResponseBody, @RestController, ResponseEntity |