gwooden_코린이
스프링_MVC, 템플릿 엔진_입문NO.6 본문
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
'스프링 > 인텔리제이 스프링 입문 1편' 카테고리의 다른 글
스프링_API_입문NO.7 (0) | 2022.12.11 |
---|---|
스프링_정적컨텐츠_입문NO.5 (0) | 2022.12.11 |
스프링_빌드&실행_입문NO.4 (0) | 2022.12.11 |
스프링_view_입문NO.3 (0) | 2022.12.11 |
스프링_라이브러리_입문NO.2 (0) | 2022.12.11 |
Comments