前提・実現したいこと
Java
Springとthymeleafを使い、問い合わせフォームを作成中です。
エラーが発生しているのですが、調べても原因がわかりません。どのようにすれば動くでしょうか。
発生している問題・エラーメッセージ
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. There was an unexpected error (type=Internal Server Error, status=500). Error resolving template [form], template might not exist or might not be accessible by any of the configured Template Resolvers org.thymeleaf.exceptions.TemplateInputException: Error resolving template [form], template might not exist or might not be accessible by any of the configured Template Resolvers
該当のソースコード
package com.example.demo.app.inquiry; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.validation.BindingResult; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestMapping; @Controller @RequestMapping("/inquiry") public class InquiryController { @GetMapping("/form") public String form(InquiryForm inquiryForm, Model model) { model.addAttribute("title", "Inquiry Form"); return "inquiry/form"; } @PostMapping("/form") public String formGoback(InquiryForm inquiryForm, Model model) { model.addAttribute("title", "Inquiry Form"); return "inquiry/form"; } @PostMapping("/confirm") public String confirm(@Validated InquiryForm inquiryForm, BindingResult result, Model model) { if(result.hasErrors()) { model.addAttribute("title", "Inquiry Form"); return "inquiry/form"; } model.addAttribute("title", "Confirm Page"); return "inquiry/confirm"; } }
package com.example.demo.app.inquiry; import javax.validation.constraints.Email; import javax.validation.constraints.NotNull; import javax.validation.constraints.Size; public class InquiryForm { @Size(min = 1, max = 20, message = "Please input 20characters or less") private String name; @NotNull @Email(message = "Invalid E-mail Format") private String email; @NotNull private String contents; public InquiryForm() { } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getContents() { return contents; } public void setContents(String contents) { this.contents = contents; } }
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title th:text="${title}">Insert title here</title> </head> <body> <div th:replace="~{block/header::headerA}"></div> <h1 th:text="${title}">title</h1> <h2 th:text="${complete}"></h2> <form method="post" action="#" th:action="@{/survey/confirm}" th:object="${surveyForm}"> <label for="age">Age:</label> <input id="age" name="age" type="number" th:value="*{age}"><br> <div th:if="${#fields.hasErrors('age')}" th:errors="*{age}"></div> <label for="email">Satisfaction:</label> <input type="radio" name="satisfaction" value="1" th:checked="*{satisfaction == 1}">1 <input type="radio" name="satisfaction" value="2" th:checked="*{satisfaction == 2}">2 <input type="radio" name="satisfaction" value="3" th:checked="*{satisfaction == 3}">3 <input type="radio" name="satisfaction" value="4" th:checked="*{satisfaction == 4}">4 <input type="radio" name="satisfaction" value="5" th:checked="*{satisfaction == 5}">5<br> <div th:if="${#fields.hasErrors('satisfaction')}" th:errors="*{satisfaction}"></div> <label for="comment">Comment:</label> <textarea name="comment" id="comment" rows="3" cols="40" th:field="*{comment}"></textarea><br> <div th:if="${#fields.hasErrors('comment')}" th:errors="*{comment}"></div> <input type="submit" value="Confirm"> </form> </body> </html>
回答1件
あなたの回答
tips
プレビュー