[점프투스프링부트] 2-15 질문 등록과 폼 질문드립니다.
안녕하세요. :)
점프 투 스프링 부트를 보고 현재 작성해보고 싶은 페이지가 있어서 작성중에 있습니다.
그런데 2-15에서 문제가 생겨 글을 올립니다.
오류 내용은 아래와 같고 코드는 아래와 같습니다.
git : https://github.com/kimothink/Groupware
JAVA CODE
DayWorkController
@GetMapping("/create")
public String dayworkCreate(DayWorkForm dayworkForm) {
return "daywork_form";
}
@PostMapping("/create")
public String dayworkCreate(@Valid DayWorkForm dayworkForm, BindingResult bindingResult) {
if (bindingResult.hasErrors()) {
return "daywork_form";
}
// TODO 질문을 저장한다.
this.dayworkService.create(dayworkForm.getSubject(), dayworkForm.getContent());
return "redirect:/daywork/list"; // 질문 저장후 질문목록으로 이동
}
daywork_form.html
<html layout:decorate="~{layout}">
<div layout:fragment="content" class="container">
<h5 class="my-3 border-bottom pb-2">업무등록</h5>
<form th:action="@{/daywork/create}" th:object="${dayworkForm}" method="post">
<div class="alert alert-danger" role="alert" th:if="${#fields.hasAnyErrors()}">
<div th:each="err : ${#fields.allErrors()}" th:text="${err}" />
</div>
<div class="mb-3">
<label for="subject" class="form-label">제목</label>
<input type="text" th:field="*{subject}" class="form-control">
</div>
<div class="mb-3">
<label for="content" class="form-label">내용</label>
<textarea th:field="*{content}" class="form-control" rows="10"></textarea>
</div>
<input type="submit" value="저장하기" class="btn btn-primary my-2">
</form>
</div>
</html>
오류 내용
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/daywork_form.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring6.processor.SpringInputGeneralFieldTagProcessor' (template: "daywork_form" - line 8, col 32)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.6.RELEASE.jar:2.0.6.RELEASE]
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring6.processor.SpringInputGeneralFieldTagProcessor' (template: "daywork_form" - line 8, col 32)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dayworkForm' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-6.0.11.jar:6.0.11]
... 74 common frames omitted
2023-08-09T15:03:33.695+09:00 ERROR 5388 --- [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/daywork_form.html]")] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dayworkForm' available as request attribute
2023-08-09T15:07:26.440+09:00 ERROR 5388 --- [nio-8080-exec-8] org.thymeleaf.TemplateEngine : [THYMELEAF][http-nio-8080-exec-8] Exception processing template "daywork_form": An error happened during template parsing (template: "class path resource [templates/daywork_form.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/daywork_form.html]")
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at java.base/java.lang.Thread.run(Thread.java:833) ~[na:na]
Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring6.processor.SpringTextareaFieldTagProcessor' (template: "daywork_form" - line 8, col 23)
at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
... 48 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring6.processor.SpringTextareaFieldTagProcessor' (template: "daywork_form" - line 8, col 23)
at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.1.1.RELEASE.jar:3.1.1.RELEASE]
... 50 common frames omitted
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dayworkForm' available as request attribute
at org.springframework.web.servlet.support.BindStatus.<init>(BindStatus.java:153) ~[spring-webmvc-6.0.11.jar:6.0.11]
... 74 common frames omitted
2023-08-09T15:07:26.444+09:00 ERROR 5388 --- [nio-8080-exec-8] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/daywork_form.html]")] with root cause
java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'dayworkForm' available as request attribute
kimo87 님 737
2023년 8월 9일 3:25 오후
daywork_form.html 템플릿의 8번째 줄을 확인해 보세요. 거기에서 오류가 났다고 되어 있네요..
-
박응용님,
2023년 8월 9일 4:43 오후
추천
,
대댓글
매개변수명 dayworkForm을 dayWorkForm으로 한번 바꾸어 보세요.
-
박응용님,
2023년 8월 10일 1:00 오전
추천
,
대댓글
@박응용님 님 말씀하신 내용으로 수정 후 이상 없이 잘 되었습니다. dayworkForm -> dayWorkForm으로 바꿔야하는지 어떻게 아신거죠 변수명은 dayworkForm인데요!
-
kimo87님,
2023년 8월 11일 2:40 오후
추천
,
대댓글
@kimo87님 폼 변수명은 카멜케이스로 정확하게 바인딩해야 하는 것 같습니다. 자세한건 좀 찾아봐야 할듯 하네요.
-
박응용님,
2023년 8월 11일 3:00 오후
추천
,
대댓글
@박응용님 감사합니다.
-
daehoon.seong님,
2023년 8월 24일 4:02 오후
추천
,
대댓글