前提
日付検索機能のバリデーションを実装しようとしているですが、以下のようなエラーが発生しています。スペルミスやフォームデータの受け渡しの有無の確認をしたのですが、解決できませんでした。
わかる方教えていただきたいです。
実現したいこと
バリデーションのエラーメッセージを表示させる。
発生している問題・エラーメッセージ
Exception evaluating SpringEL expression: "reportDate" (template: "inventory/index" - line 18, col 46)
該当のソースコード
Form
1@Data 2public class InventorySearchReq{ 3 4 @NotNull (message = "日付を設定してください。") 5 @DateTimeFormat(pattern = "yyyy-MM-dd") 6 @PastOrPresent(message = "日付が未来に設定されています。") 7 private LocalDate reportDate; 8 9}
Controller
1@PostMapping("/id_search") 2 public String search( 3 @Validated @ModelAttribute InventorySearchReq inventorySearchReq, 4 BindingResult result, 5 Model model, 6 RedirectAttributes redirectAttributes 7 ) { 8 9 if (result.hasErrors()) { 10 model.addAttribute("inventorySearchReq", inventorySearchReq); 11 model.addAttribute("title", "在庫 照会"); 12 13 return "inventory/index"; 14 }
Thymeleaf
1<form method="POST" th:action="@{/inventory/id_search}" th:object="${inventorySearchReq}"> 2 <label>日付:</label> 3 <input type="date" name="reportDate" th:value="*{reportDate}"/> 4 <input type="submit" class="btn btn-primary" value=" 検索 "> 5 <div th:if="${#fields.hasErrors('reportDate')}" th:errors="*{reportDate}"></div> 6 </form>
試したこと
スペルミス、フォームデータの受け渡しの有無の確認
補足情報(FW/ツールのバージョンなど)
java11 spring boot thymeleaf
あなたの回答
tips
プレビュー