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>
@Controller
public class HelloController {
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam("name") String name, Model model) {
model.addAttribute("name", name);
return "hello-template";
}}
resources/template/hello-template.html
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>
http://localhost:8080/hello-mvc?name=spring
→ 나는 8090
꿀팁 단축키 : intelliJ에서 Ctrl + Shift + Enter ⇒ 자동완성...!
단축키 : Alt + Insert ⇒ getter + setter 생성
@Controller
public class HelloController { @GetMapping("hello-string")
@ResponseBody
public String helloString(@RequestParam("name") String name) {
return "hello " + name;
}
}
@Controller
public class HelloController {
@GetMapping("hello-api")
@ResponseBody
public Hello helloApi(@RequestParam("name") String name) {
Hello hello = new Hello();
hello.setName(name);
return hello;
}
static class Hello {
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
}
클라이언트의 HTTP Accept 해더와 서버의 컨트롤러 반환 타입 정보 둘을 조합해서 HttpMessageConverter가 선택된다.
key : value로 이루어진 구조
XML과 충돌하다가.. 최근에는 거의 json방식으로 통일이 되었다.
→ 프로젝트하면 json을 사용하세요~ 옛 legacy프로젝트만 xml씀