목차
정적 페이지 제작
static > static.html 제작 | 8080:static.html |
|---|
정적 페이지의 구동 과정
Controller
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam("name") String name, Model model){
model.addAttribute("name", name);
return "hello-template";
}
//controller
<!DOCTYPE HTML>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'hello ' + ${name}"> hello empty!</p>
</body>
</html>
//resources/templates/hello-template.html
hello-mvc | hello-mvc?name=spring!! |
|---|
hello-mvc가 호출될 시 name 파라미터를 받아 hello-template에 model("name", name)로 전송하게 된다.
MVC, 템플릿 엔진 구동 과정
String 전송
@GetMapping("hello-string")
@ResponseBody // http body에 직접 삽입
public String helloString(@RequestParam("name") String name,Model model){
return "hello" + name;
}
//string 컨트롤러

JSON 전송
@GetMapping("hello-api")
@ResponseBody
public Hello helloApi(@RequestParam("name") String name){
Hello hello = new Hello();
hello.setName(name);
return hello;
}
//api 컨트롤러
static class Hello{
private String name;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
//자바 빈 표준 방식(프로퍼티 접근 방식)

@ResponseBody 구동 과정