뷰 - 화면을 그리는데에 모든 역량 집중
컨트롤러, 모델 - 비즈니스 로직과 관련이거나 내부적으로 처리하는데 집중
/hello-spring/src/main/java/hello/hellospring/controller/HelloController.java
package hello.hellospring.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-templates";
}
}
/hello-spring/src/main/resources/templates/hello-templates.html
<html xmlns:th = "http://www.thymeleaf.org">
<body>
<p th:text="'hello ' + ${name}">hello! empty</p>
</body>
</html>
url : http://localhost:8080/hello-mvc?name=spring! 입력시 hello spring! 출력
'스프링' 카테고리의 다른 글
| 컴포넌트 스캔과 자동 의존관계 설정 (0) | 2024.01.20 |
|---|---|
| 회원 리포지토리 테스트 케이스 이클립스로 Junit Test 실행해보기 (0) | 2024.01.11 |
| API (0) | 2024.01.11 |
| cmd창에서 빌드하고 실행해보기 (0) | 2024.01.10 |
| thymeleaf 템플릿 엔진 동작(기본) (0) | 2024.01.10 |