스프링 입문 - 프로젝트 환경설정 #1
-
Controller 를 사용하여 웹 정적 페이지를 작성한다.
package hello.hellospring.controller; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.GetMapping; @Controller public class HelloController { @GetMapping("hello") public String helle(Model model) { model.addAttribute("data", "hello!! haha"); return "hello"; } }
-
templates 라이브러리를 통해 html 작성
<!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="'안녕하세요. ' + ${data}" >안녕하세요. 손님</p> </body> </html>
- 여기서
&{data}
는 Controller 의model.addAttribute("data", "hello!! haha");
의 리턴값으로 문자를 변환한다. - 변환된 문자는
viewResolver
가 화면을 찾아서 처리한다.- 스프링 부트 템플릿엔진 기본 viewName 매핑
resources:templates/ +{ViewName}+ .html
- 여기서
thymeleaf 템플릿엔진 동작 확인
Author And Source
이 문제에 관하여(스프링 입문 - 프로젝트 환경설정 #1), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@jsje02/스프링-입문-프로젝트-환경설정-1저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)