06 MVC와 템플릿엔진

이연희·2022년 1월 13일
0

Spring

목록 보기
6/105

MVC: Model, View, Controller

View는 화면을 그려내는 것에 모든 역량을 집중시켜야 하고, Controller는 모델 관련 비지니스 로직 또는 내부적인 것을 처리하는 것에 집중해야 함

✅ (기본 RequestParam(value = "name", required=true)로 설정 돼 있음)

@GetMapping("hello-mvc")
    public String helloMVC(@RequestParam(value = "name") String name, Model model){//model에 담으면 view에서 렌더링할 때 씀
        model.addAttribute("name",name);//key,name
        return "hello-template";
    }

✅ 모델의 key값이 name인 것을 찾아서 치환해 줌

<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>

✅ HTTP GET 방식에서 변수 받는 법: '?name=SPRING!'

✅ MVC, 템플릿 엔진 이미지

✅ 템플릿 엔진 변환 후 HTML을 웹 브라우저에 넘겨줌


스프링입문06(김영한)

profile
공부기록

0개의 댓글