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

파일 그대로 웹브라우저에 전달. 서버에서 수정 불가능
: Model, View, Controller
//[main] - [java] - [hello] - [hellospring] - [controller] - [HelloController]
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class HelloController {
@GetMapping("hello-mvc") //외부에서 파라미터를 받음
public String helloMVC(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "hello-template";
}
}
<!-- [main] - [resources] - [templates] - [hello-template] -->
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>


?name=value 를 입력하면 정상 작동

❗ hello-template의 'hello empty'의 역할은?
thymleaf의 장점 중 하나가 html 파일을 html을 서버 없이 열 수 있다는 것인데, 그 때 나오는 내용(껍데기값)이 바로 'hello empty' 부분이다. 후에 템플릿 엔진으로 정상 동작하면 text 값으로 내용이 치환된다.
Absolute Path Copy로 주소 복사 후 주소창에 열기
//[main] - [java] - [hello] - [hellospring] - [controller] - [HelloController]
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@GetMapping("hello-string")
@ResponseBody //http의 bdoy부에 이 내용(데이터)를 직접 넣어주겠다는 의미
public String helloString(@RequestParam("name") String name) {
return "hello " + name;
}
}

❗ 템플릿엔진 vs API 차이
- 템플릿엔진의 소스코드
- API의 소스코드
결과값은 같지만 내부 소스코드가 다름
//[main] - [java] - [hello] - [hellospring] - [controller] - [HelloController]
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
@GetMapping("hello-api")
@ResponseBody
public Hello helloApi(@RequestParam("name") String name) {
Hello hello = new Hello();
hello.setName(name);
return hello; //문자가 아닌 객체를 return
}
static class Hello {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}


@ResponseBody가 없으면 Controller가 viewResolver한테 전달
@ResponseBody가 있으면 HttpMessageConverter가 처리