gwooden_코린이

스프링_MVC, 템플릿 엔진_입문NO.6 본문

스프링/인텔리제이 스프링 입문 1편

스프링_MVC, 템플릿 엔진_입문NO.6

gwooden22 2022. 12. 11. 19:54
728x90

MVC : Model, View, Controller

mvc 스타일로 많이 작업함

 

Controller

@Controller
public class HelloController {
 @GetMapping("hello-mvc")
 public String helloMvc(@RequestParam("name") String name, Model model) {
 model.addAttribute("name", name);
 return "hello-template";
 }
}

 

View

<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>

 

 

hello-mvc 겟맵핑

    @GetMapping("hello-mvc")
    public String helloMvc(@RequestParam("name") String name, Model model) {
        model.addAttribute("name", name);
        return "hello-template";
    }
}

 

2022-12-11 22:53:34.745  WARN 17040 --- [nio-8080-exec-4] .w.s.m.s.DefaultHandlerExceptionResolver : Resolved [org.springframework.web.bind.MissingServletRequestParameterException: Required request parameter 'name' for method parameter type String is not present]

컨트롤 + P 단축키를 이용해 오류가 발생한 부분에 어떤 매개변수가 필요한지 알 수 있습니다.

 

 

<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>

인프런 김영한 선생님 강의 자료

 

728x90
Comments