前提・実現したいこと
spring boot でthymeleafを使って値の受渡しをしたいのですが、一つ目のhtmlの<input type="text" th:field="*{userId}" />の部分を追加すると、エラーが出て画面遷移が上手く行きません。
どなたかよろしければご教示下さい
発生している問題・エラーメッセージ
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/signUp.html]") at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:241) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE] at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parseStandalone(AbstractMarkupTemplateParser.java:100) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
Caused by: org.attoparser.ParseException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "signUp" - line 9, col 28) at org.attoparser.MarkupParser.parseDocument(MarkupParser.java:393) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.attoparser.MarkupParser.parse(MarkupParser.java:257) ~[attoparser-2.0.5.RELEASE.jar:2.0.5.RELEASE] at org.thymeleaf.templateparser.markup.AbstractMarkupTemplateParser.parse(AbstractMarkupTemplateParser.java:230) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE] ... 52 common frames omitted
Caused by: org.thymeleaf.exceptions.TemplateProcessingException: Error during execution of processor 'org.thymeleaf.spring5.processor.SpringInputGeneralFieldTagProcessor' (template: "signUp" - line 9, col 28) at org.thymeleaf.processor.element.AbstractAttributeTagProcessor.doProcess(AbstractAttributeTagProcessor.java:117) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE] at org.thymeleaf.processor.element.AbstractElementTagProcessor.process(AbstractElementTagProcessor.java:95) ~[thymeleaf-3.0.11.RELEASE.jar:3.0.11.RELEASE]
Caused by: java.lang.IllegalStateException: Neither BindingResult nor plain target object for bean name 'userInfoForm' available as request attribute
該当のソースコード
<!DOCTYPE html> <html lang="ja" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Sign in</title> </head> <body> <h1>login</h1> <a href="/signUp">sign up</a> </body> </html>
<!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title>Sign up</title> </head> <body> <div th:text="${name}"></div> <form method="post" th:action="@{/signInConfirm}" th:object="${userInfoForm}" > <input type="text" th:field="*{userId}" /> <input type="submit" value="Submit" /> </form> </body> </html>
@Controller public class SignUpController { @RequestMapping(value = "/signUp",method = RequestMethod.GET) public String moveSignUp(Model model){ model.addAttribute("name","hogehoge"); return "signUp"; } @RequestMapping(value = "signUpConfirm", method = RequestMethod.POST) public String signUpConfirm(@ModelAttribute UserInfoForm userInfoForm, Model model){ return "signUpConfirm"; } }
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Sign up Confirm</title> </head> <body> <h1>Sign Up Confirm</h1> </body> </html>
package dev.create.form; import javax.annotation.Resource; @Resource public class UserInfoForm { private String userId = ""; public String getUserId() { return userId; } public void setUserId(String userId) { this.userId = userId; } }

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/08 03:37
2018/11/08 05:49
2018/11/08 06:03
2018/11/08 06:50
2018/11/08 09:16