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 이 출력됨

 

 

 

 

 

'Java > Spring' 카테고리의 다른 글

[스프링 웹 개발 기초]API  (0) 2021.03.24
@RequestParam, 커맨드객체  (0) 2021.03.24
[스프링 웹 개발 기초] 정적 컨텐츠  (0) 2021.03.24
[View 환경설정] view 기본 동작환경  (0) 2021.03.24
JAR WAR 차이  (0) 2021.03.24