Controller는 기본적으로 resouces > templates 에서 .html 을 찾는다.

@GetMapping("/static-hello")
public String hello() {
return "hello.html";
}
templates 에는 hello.html 이 없다!
오류 발생: http://localhost:8080/hello/static-hello
만약 resouces > static 에 있는 .html 을 찾기 위해선
Controller 를 통해서 접근하지 않고, html 로 바로 접근한다!!
http://localhost:8080/hello.html
http://localhost:8080/hello/static-hello
Controller를 통해 접근이 가능하다.
하지만 이미 만들어진, 변하지 않는 정적 페이지를 굳이 Controller를 통해 접근해야할까?
그냥 바로이름.html로 접근하는 것이 좋다!
@GetMapping("/html/templates")
public String htmlTemplates() {
return "hello";
}
hello.html 이지만 .html 를 생략하고 바로 html의 이름을 return 하면 된다.(return 타입이 String)
return 타입이 String 일 때, 리턴을 하면 templates 에서 html을 찾는다.
@GetMapping("/hello")
public String hello() {
return "hello";
}
http://localhost:8080/hello하게 되면hello.html을resource > templates에서 찾아서hello.html을 보여준다.

return 타입이 String 일 때, String 문자열을 출력한다.
@GetMapping("/hello")
@ResponseBody
public String hello() {
return "String hello 나는 문자열이야";
}
http://localhost:8080/hello을 하게 되면 hello 문자열을 보여준다.
