[스프링] 웹 개발 기초 2

기록지·2022년 12월 19일
0

스프링

목록 보기
2/4

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

hello! empty

--> http://localhost:8080/hello-mvc?name=spring~~
name 값에 넘겨주는 파라미터에 따라 ${name} 값이 바뀐다.

<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>

0개의 댓글