반응형 Templates2 TIL_ResponseBody #Spring @ResponseBody는 왜 쓸까요? @GetMapping("/body/html") @ResponseBody public String helloStringHTML() { return "" + "" + "" + " Hello, 정적 웹 페이지!!" + ""; } 원래는 View를 보여주나 ResponseBody라고 해주면 View를 제공해 주는 것이 아니라 String내용을 body에 채워준다 만약 View를 통해서 HTML파일을 통해서 내려주는 경우에도 HTML이 내려오는 것이 아닌 텍스트 내용만 내려오는 것이다 그렇다면 왜 ResponseBody를 쓸까? @ResponseBody를 해주면 View를 통과하지 않는다. 즉,템플릿엔진으로 넘기는 것이 아니라 메시지를 바로 body에 넣어주게 된다 2022. 8. 4. [TIL] SpringMVC동작이해 static폴더에 존재하던 hello.html이 나오지 않다가 어떻게 위처럼 templates에 복사본 하나를 두었다고 출력이 되는 것일까? @GetMapping("/html/templates") public String htmlTemplates() { return "hello"; } 타임리프 default 설정 - prefix : classpath:/templates/ - suffix: .html resources/templates/hello.html hello가 들어오면 resources의 templates에서 찾는데 view name이 hello자리에 들어가고 view name 뒤에 html을 붙여서 찾는다.이것이 타임리프 default설정인데 폴더나 뒤에붙는 html을 바꿀 수 있다 다시한번 정리.. 2022. 8. 4. 이전 1 다음 반응형