스프링 웹 개발 기초

Jimin·2022년 10월 4일
0

스프링 - inflearn

목록 보기
2/15
post-thumbnail

정적 컨텐츠(static content)

웹 브라우저에서 localhost:8080/hello-static.html 을 내장 톰캣 서버로 요청

1. 먼저 스프링 컨테이너에서 hello-static 관련 컨트롤러 찾음
2. 관련 컨틀롤러가 없을시에, resources: static/hello-static.html을 찾는다.

hello-static-html을 웹 브라우저에 리턴한다.


MVC와 템플릿 엔진

MVC: Model, View, Controller

Controller

@Controller
public class HelloController {
    
    @GetMapping("hello")
    public String hello(Model model){
        model.addAttribute("data", "hello!!");
         return "hello";
    }
}

View

<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>static content</title>
</head>
<body>
정적 컨텐츠입니다.
</body>
</html>

MVC, 템플릿 엔진 이미지


API

@ResponseBody 사용 원리

웹 브라우저에서 localhost:8080/hello-api 요청

톰캣 내장 서버

Controller 에서 찾는데, @ResponsBody 가 붙어있으면 HttpMessageConverter 가 실행된다.

객체 가 return되는 경우 → JsonConverter 실행
문자열 이 return되는 경우 → StringConverter 실행

profile
https://github.com/Dingadung

0개의 댓글