Java/[인프런] Spring 강의
[SpringBoot] #03 - View 환경설정
냠냠쿠
2023. 8. 10. 22:29
728x90
https://www.inflearn.com/course/%EC%8A%A4%ED%94%84%EB%A7%81-%EC%9E%85%EB%AC%B8-%EC%8A%A4%ED%94%84%EB%A7%81%EB%B6%80%ED%8A%B8/dashboard
📌 Welcome Page 만들기
- resources/static/index.html 에 넣으면 자동으로 welcome page 기능 제공
<!DOCTYPE HTML>
<html>
<heda>
<title> hello world </title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</heda>
<body>
hello
<a href="/hello">world</a>
</body>
</html>
필요한 자료 찾는 법
https://spring.io/projects/spring-boot
https://docs.spring.io/spring-boot/docs/current/reference/html/
여기서 관련 된 페이지에 들어가서 Contrl+ F로 검색하면 됨
📌 템플릿 엔진 사용
- main - java - hello.hellospring - controller(패키지생성) - 컨트롤러를 생성하고
resources - templates 에서 html파일을 만들어 위와 같이 정의를 하는 경우 attributeName 을 attrubuteValue로 리턴한다.
📌 동작 환경
- 웹 브라우저에서 localhost:8080/hello 라고 던진다
- spring boot (톰캣 서버 내장) 톰캣 에서 spring 에게 물어본다.
- spring은 getMapping 을 통해 매칭을 찾는다.
- 매칭이 되면 컨트롤러가 실행된다.
- return 값을 resources - templates 에서 찾아 랜더링 한다.
- 컨트롤러에서 리턴 값으로 문자를 반환하면 viewResolver가 화면을 찾아 처리
기본 세팅 : resources:templates/ +{ViewName}+ .html 이 열리게 됨.
** spring-boot-devtools 라이브러리 추가 시 html 파일을 컴파일만 해주면 서버 재시작 없이 View 파일 변경 가능
빌드 → Recompile
728x90