Spring
[Spring] Error resolving template 문제 해결
Dong's Universe
2023. 12. 24. 23:34
- 문제
[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";
// *************************** //
}