BackEnd/Spring & Springboot Study
[스프링 웹 개발 기초] - 06. 정적 컨텐츠
JunGi Jeong
2021. 4. 9. 20:11
MVC와 템플릿 엔진
- MVC: Model, View, Controller
Controller
@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
MVC Template engine - mvc패턴을 통해 html을 동적으로 바꿔서 제공
관심사 분리
View는 화면을 그리는데 모든 역량
Controller, Model은 비지니스 로직 내부
예전에는 View에 (JSP) Scriptlet(<% %>)같은거 JSTL(<%= %>) c:set c:if 등등
요즘엔 아예 Thymeleaf (Template Engine) or React(웹 프레임워크, JS Library)등으로 전환하는거 같다.