웹 개발(정적 컨텐츠, MVC&템플릿 엔진, API)
package hello.hellospring.controller;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
@Controller
public class HelloController {
//웹 애플리케이션에서 /hello가 들어오면 이 메서드를 호출해준다!!!!
@GetMapping("hello")
public String hello(Model model){//스프링이 Model이라는 것을 만들어서 넣어준다.
model.addAttribute("data","흔나 화이팅!!!");//data로 hello를 넘긴다.
return "hello";//현재 컨트롤러. 템플릿에서 hello.html를 찾는다. 찾아서 렌더링한다.
}
@GetMapping("hello-mvc")
//url을 파라미터로 바꿔본다. Model을 매개변수로 담으면 뷰에서 렌더링할 때 쓴다!
public String helloMvc(@RequestParam("name") String name, Model model){
model.addAttribute("name",name);
return "hello-template";//hello-template으로 간다!
}
}



Last updated