
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>static-content</title>
</head>
<body>
<h1>정적 컨텐츠</h1>
<p>정적 컨텐츠 입니다.</p>
</body>
</html>

controller
package Portfolio.PortfolioSpring.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") // 주소창에서 hello 라는 주소가 들어오면 실행되는 메서드
public String hello(Model model){
model.addAttribute("data" , "Hello!!"); // data를 hello 라고 넘긴다.
return "hello"; // hello를 리턴
}
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam("name") String name , Model model){ // requestparam은 웹 사이트 url에서 받은 파라미터를 사용한다는 뜻이다.
model.addAttribute("name" , name);
return "hello-template";
}
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>hello-mvc</title>
</head>
<body>
<p th:text="'hello ' + ${name}">Hello! empty</p>
</body>
</html>

문자를 넘길때
@GetMapping("hello-string") @ResponseBody // http 통신 프로토콜 규칙에 의해 body에 직접 데이터를 넣겠다. public String helloString(@RequestParam("name") String name){ return "hello " + name; // hello spring }객체를 넘길때(JSON)
@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; } }