[Spring] Error resolving template 문제 해결
2023. 12. 24. 23:34ㆍSpring
- 문제
[THYMELEAF][http-nio-8080-exec-1] Exception processing template "/contents/createContentForm.html":
Error resolving template [/contents/createContentForm.html],
template might not exist or might not be accessible by any of the configured Template Resolvers
- 원인
Mapping 메소드의 return을 "/url"로 해서 그렇다.
이 경우 절대경로로 인식한다.
예를 들어, 다음과 같다.
@GetMapping("/new")
public String createForm(Model model) {
model.addAttribute("contentForm", new ContentForm());
// *************************** //
return "/contents/createContentForm.html";
// *************************** //
}
- 해결
Mapping 메소드의 return을 "url"로 바꾼다.
이 경우 상대경로로 인식이 돼 "...templates/"부터 시작한다.
예를 들어, 다음과 같다.
@GetMapping("/new")
public String createForm(Model model) {
model.addAttribute("contentForm", new ContentForm());
// *************************** //
return "contents/createContentForm.html";
// *************************** //
}
'Spring' 카테고리의 다른 글
[Spring] MVC 프레임워크 프론트 컨트롤러에 대한 나름의 이해 (0) | 2024.01.04 |
---|---|
[Spring] spring 프로젝트 jar로 배포하기 (0) | 2023.12.24 |
[Spring] h2를 간단하게 메모리로 돌리기 (0) | 2023.12.24 |
[Spring] @PathVariable에 대한 나름의 이해 (0) | 2023.12.24 |
[Spring] 타임리프로 이미지 넣기 (0) | 2023.12.24 |