강의

멘토링

커뮤니티

Inflearn Community Q&A

heeguk957283's profile image
heeguk957283

asked

Spring for Beginners - Learn Spring Boot, Web MVC, and DB Access Technology with Code

Static Content

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

Written on

·

287

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으로 가게 되는지 궁금합니다!

javaspringspring-bootMVC

Answer 1

1

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

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


감사합니다.

heeguk95님의 프로필 이미지
heeguk95
Questioner

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

---

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

---

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

---

결과

 

 

heeguk95님의 프로필 이미지
heeguk95
Questioner

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

heeguk957283's profile image
heeguk957283

asked

Ask a question