MVCλ Model
, View
, Controller
μ μ½μλ‘, μ ν리μΌμ΄μ
μ ꡬμ±νλ μ£Όμ μν μ λΆλ¦¬ν μν€ν
μ² ν¨ν΄μ
λλ€.
κ΄μ¬μ¬μ λΆλ¦¬(Separation of Concerns, SoC)
κ°κ°μ μν μ λ
립μ μΌλ‘ λλμ΄, μ½λ κ°μ μν₯λλ₯Ό μ€μ΄λ κ²μ΄ ν΅μ¬μ
λλ€.
μ΄λ―Έμ§ μΆμ²: μΈνλ° κ°μ(μ€νλ§ μ
λ¬Έ - μ½λλ‘ λ°°μ°λ μ€νλ§ λΆνΈ, μΉ MVC, DB μ κ·Ό κΈ°μ )
localhost:8080/hello-mvc
μ κ°μ μμ²μ 보λ Controller
μ λ§€νλ κ²½λ‘κ° μλμ§ νμΈ return "ν
νλ¦Ώ μ΄λ¦"
μΌλ‘ λ°ν <!-- src/main/resources/templages/ μλμ νμΌ μμ± -->
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Hello Template</title>
</head>
<body>
<p th:text="'hello '+ ${name}">hello Empty</p> <!-- ν΄λΉ μ½λλ Thymeleaf λ¬Έλ²μΈλ° μλ μ°Έκ³ νλͺ© λ§ν¬ νμΈ λΆνλ립λλ€. -->
</body>
</html>
controller
ν¨ν€μ§ μμ± λ° νμΌ μμ±/*
1. νλ‘μ νΈ μλμ controller ν¨ν€μ§ μμ±
2. 'HelloController'λΌλ μ΄λ¦μΌλ‘ ν΄λμ€ μμ±
*/
Controller
μ μ½λ μΆκ°(HelloController.java)/* 2. ν
νλ¦Ώ μμ§ λ°©μ */
@GetMapping("hello-mvc")
public String helloMvc(@RequestParam(value = "name", required = true) String name, Model model) {
model.addAttribute("name", name);
return "hello-template";
}
localhost:8080/hello-mvc?name=μνλμ΄λ¦
νΈμΆ