resources > static 경로에 index.html file을 만들어준다.

기본 html file을 작성해 두고, 서버를 끄고 다시 켜면 우리가 방금 작성한 html file의 결과물을 볼 수 있다.

7.1.6. 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.

https://docs.spring.io/spring-boot/docs/2.5.7/reference/html/features.html#features

src > main > java > hello.hellospring

HelloController 를 만들어주고 아래와 같이 작성한다.

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 hello(Model model) {
        model.addAttribute("data", "hello");
        return  "hello";
    }
}

컨트롤러를 만들 땐 @Controller 라는 에노테이션을 붙여준다.

@GetMapping("hello") 은 /hello 라는 get 요청에 대해 아래 코드를 맵핑해 주겠다는 에노테이션 이다.

그 후 인자로 model을 받고, 해당 모델의 Attribute를 키는 data 값은 hello로 넣어준다

 public String hello(Model model) {
  model.addAttribute("data", "hello");
  return  "hello";
}

리턴을 문자열로 하면,

return  "hello";

resources > tempates 의 파일 이름과 맵핑된다.