Java/Spring
[스프링 웹 개발 기초]MVC와 템플릿 엔진
코딩공부
2021. 3. 24. 02:04
MVC: Model, View, Controller
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
resources/template/hello-template.html
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>
실행
- http://localhost:8080/hello-mvc?name=spring
thymeleaf를 기능
서버 연결없이 html을 실행(절대경로로)하면 hello! empty 가 출력됨
서버 연결하여 실행하면 hello spring 이 출력됨