반응형
MVC: Model, View, Controller
Cotroller 작성
@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">
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</head>
<body>
<p th:text="'hello ' + ${name}" >hello! empty</p>
</body>
</html>
파라미터를 url에 안적을때는 에러가 발생
인텔리제이에서 ctrl + p 명령어를 통해서 파라미터 정보를 확인이 가능하다
required가 기본적으로 true이기 때문에 필수로 데이터 입력을 해주어야한다.
값이 정상적으로 입력이 되었다면 template폴더안에 해당 html파일을 찾아 반환해준다.
아래는 정상 동작
반응형
'코드로 배우는 스프링 부트 - 인프런' 카테고리의 다른 글
비즈니스 요구사항 정리 (0) | 2022.08.05 |
---|---|
API (0) | 2022.08.04 |
정적 컨텐츠 (0) | 2022.08.03 |
스프링부트 프로젝트 jar 파일로 빌드하고 실행하기 (0) | 2022.08.01 |
view 환경설정 (0) | 2022.08.01 |