프로그래밍/SpringMVC_기초
MVC와 템플릿 엔진
ILove_NS_MoKa
2023. 10. 13. 23:20
MVC: Model, View, Controller
java-> HelloController 추가
1
2
3
4
5
|
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam(name = "name") String name,Model model){
model.addAttribute("name",name);
return "hello-template";
}
|
cs |
resources\templates\hello-template.html (파일 추가)
1
2
3
4
5
|
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>
|
cs |
실행
http://localhost:8080/hello-mvc?name=test!!
http://localhost:8080/hello-mvc?name=test!!
들어가면
내장톰켓 서버에서 -> 스프링 컨테이너 로 던짐
스프링 컨테이너는 hello-mvc 이 HelloController 에 맵핑이 돼있어서 호출함
key = name
값 = test!!
위 두값을 ViewResolver 넘김
return "hello-template"; << 을찾고
랜더링을 해서 HTML 변환후 웹브라우저 넘긴다
hello test!! 변환된걸 볼수있다