= 클라이언트의 요청에 따라 서버에서 이를 처리하는 역할
= 웹페이지를 화면에 보여주고(View) 클라이언트의 요청을 받아 처리하고(Controller) 데이터 관리 역할(Model)
1) 확장자 mustache = 뷰 템플릿 엔진
resources/templates/greetings.mustache
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title></head>
<body>
<h1>홍팍님, 반갑습니다!</h1>
</body>
</html>
@GetMapping("/hi") — URL 요청 접수
public String niceToMeetYou(){
return "greetings"; //greeting.mustache를 반환하려면 파일이름인 greetings를 반환 //그러면 서버가 templates 디렉터리에서 뷰템플릿 엔진을 반환
}
= 뷰 템플릿 엔진에 변수 삽입 ———→ {{변수명}}
@GetMapping("/hi")
public String niceToMeetYou(Model model){
model.addAttribute("username","hongpark");
return "greetings";
}
Model 클래스를 임포트한후 모델로 변수 등록
ex) model.addAttribute(”Username”,”hongpark)
@Controller — 1. 컨트롤러 선언
public class FirstController { — 2. URL요청 접수
@GetMapping("/hi")
public String niceToMeetYou(Model model){ — 3.메서드 수행 — 4. 모델 객체
model.addAttribute("username","hongpark"); — 5. 모델 변수 등록
return "greetings"; —- 6. 뷰 템플릿 페이지 반환
}