๋ฐฑ์—”๋“œ(Back-End) ๊ฐœ๋ฐœ/SpringBoot

[SpringBoot] 2.2_MVC์™€ ํ…œํ”Œ๋ฆฟ ์—”์ง„

rabo93 2025. 2. 25. 13:29
MVC ๋ž€? Model, View, Controller

 

  • Controller
package hello.hello_spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class HelloController {

    @GetMapping("hello-mvc")
    public String helloMvc(@RequestParam("name") String name, Model model) {
        model.addAttribute("name", name);
        return "hello-template";
    }

}
  • View
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<body>
<p th:text="'์•ˆ๋…•ํ•˜์„ธ์š”.' + ${data}"> hello! empty</p>
</body>
</html>