• 카테고리

    질문 & 답변
  • 세부 분야

    백엔드

  • 해결 여부

    미해결

정적컨텐츠 관련 질문이요!

22.02.09 17:16 작성 조회수 214

0

@Controller
public class HelloController {
@GetMapping("hello-static")
public String hello(Model model) {
model.addAttribute("data", "hello!!");
return "hello";
}
}

위와 같이 컨트롤러를 만들었습니다.

따라서, localhost:8080/hello-static 을 입력하면
template/hello.html로 이동되게 설정했습니다.

하지만, localhost:8080/hello-static.html을 입력하면 template/hello.html로 이동되지 않고 static/hello-static.html로 이동이 됩니다.

강의 내용에 따르면 localhost:8080/hello-static.html을 입력했을 때 hello-static 관련 컨트롤러가 없는 경우에 static/hello-static.html로 이동된다고 하신것으로 기억합니다. 그런데 hello-static 컨트롤러가 있는데도 왜 static으로 가게 되는지 궁금합니다!

답변 1

답변을 작성해보세요.

1

OMG님의 프로필

OMG

2022.02.09

안녕하세요. heeguk95님, 공식 서포터즈 OMG입니다.

명시적으로 리소스(hello-static.html) url 요청을 하였기 때문에 resources/static에 존재하는 hello-static.html을 우선적으로 찾게 됩니다.


감사합니다.

heeguk95님의 프로필

heeguk95

질문자

2022.02.09

그러면 강의에서 말씀해주신 것 처럼 hello-static 관련 컨트롤러가 있어서 hello-static.html로 가지 않으려면 주소창에 어떻게 입력을 해야하나요?

OMG님의 프로필

OMG

2022.02.09

---

1번에 해당하는 hello-static관련 컨트롤러입니다. 

---

1번이 있으면, templates하위에 있는 hello-static.html을 찾아가고, 없으면 static/hello-static을 찾아갑니다.

---

결과

 

 

heeguk95님의 프로필

heeguk95

질문자

2022.02.10

친절한 답변 감사합니다! 이해 됐어요ㅎㅎ