Welcome Page는 도메인으로 들어왔을 때 첫 화면입니다.
스프링부트는 resources/static 폴더에 index.html을 넣어주면 Welcome Page로 해줍니다.
<!DOCTYPE HTML>
<html>
<head>
<title>Hello</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
</head>
<body>
Hello
<a href="/hello">hello</a>
</body>
</html>
그리고 서버를 껐다가 키면 Welcome Page가 제대로 나옵니다.
스프링부트는 스프링 생태계를 감싸서 편리하게 사용할 수 있도록 도와주는데 스프링이 사실 자바 웹 애플리케이션 개발과 관련된 전반에 대한 생태계를 제공합니다. 그래서 머리속에 담을 수 없고 필요한 것을 찾는 능력이 필요합니다. 메뉴얼에서 내용을 찾을 수 있어야 합니다.
<aside> ✏️ [참고]
Welcome Page
Spring Boot supports both static and templated welcome pages. It first looks for an index.html
file in the configured static content locations. If one is not found, it then looks for an index
template. If either is found, it is automatically used as the welcome page of the application.
Spring Boot는 정적 및 템플릿 시작 페이지를 모두 지원합니다. 먼저 index.html구성된 정적 컨텐츠 위치에서 파일을 찾습니다 . 하나가 발견되지 않으면 index템플릿 을 찾습니다 . 둘 중 하나가 발견되면 자동으로 애플리케이션의 시작 페이지로 사용됩니다.
위에서 한 것은 정적 페이지입니다. 적어놓은 파일을 웹 서버가 그대로 웹 브라우저에 응답을 주는 것입니다.
템플릿 엔진을 쓰면 루프를 넣는 식으로 원하는대로 모양을 바꿀 수 있습니다.
[참고]
이제 동작하고 프로그래밍 되는 화면을 만들어봅시다.
controller 패키지를 하나 만들고 HelloController 클래스를 만듭니다.
@Controller //...1
public class HelloController {
@GetMapping("hello") //...2
public String hello(Model model) { //...3
model.addAttribute("data", "hello!!"); //...4
return "hello"; //...5
}
}