springでhasErrorsメソッドを使ったらエラーが出ました
htmlでhasErrorsメソッドを使うには何かimportしなくていけないのでしょうか
それともmodelのほうに問題があるのでしょうか。
そもそも環境が設定が間違っている可能性が高いのでしょうか。
参考に一番高い可能性を教えてくください。
エラーコード
org.springframework.expression.spel.SpelEvaluationException: EL1004E: Method call: Method hasErrors(java.lang.String) cannot be found on type org.thymeleaf.spring5.expression.SPELContextMapWrapper
ソースコード
<!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"></meta> <!-- Bootstrapの設定 --> <link th:href="@{/webjars/bootstrap/3.3.7-1/css/bootstrap.min.css}"rel="stylesheet"></link> <script th:src="@{/webjars/bootstrap/3.3.7-1/css/bootsrap.min.js}"></script> <script th:src="@{/webjars/jquery/1.11.1/jquery.min.js}"></script> <script th:src="@{/webjars/bootstrap/3.3.7-1/js/bootstrap.min.js}"></script> <title>SignUp</title> </head> <body> <div class="col-sm-5"> <div class="page-header"> <h1>ユーザー登録画面</h1> </div> <form method="post" th:action="@{/signup}" th:object="${signupForm}"> <table class="table table-bordered table-hover"> <!-- ユーザーIDの入力エリア --> <tr> <th class="active col-sm-3">ユーザID</th> <td> <div class="form-group" th:classappend="${#fields.hasErrors('userId')}?'has-error'"> <input type="text" class="form-control" th:field="*{userId}"/> <span class="text-danger" th:if="${#fields.hasErrors('userId')}" th:errors="*{userId}"> userId error </span> </div> </td> </tr> <!-- パスワードの入力エリア--> <tr> <th class="active">パスワード</th> <td> <div class="form-group" th:classappend="${#fields.hasErrors('password')}?'has-error'"> <input type="text" class="form-control" th:field="*{password}"/> <span class="text-danger" th:if="${#fields.hasErrors('password')}" th:errors="*{password}"> password error</span> </div> </td> </tr> <!-- ユーザー名の入力エリア--> <tr> <th class="active">ユーザー名</th> <td> <div class="form-group" th:classappend="${#fields.hasErrors('userName')}?'has-error'"> <input type="text" class="form-control"th:field="*{userName}"/> <span class="text-danger" th:if="${fields/hasErrors('userName')}" th:errors="*{userName}"> userName error</span> </div> </td> </tr> <!-- 誕生日の入力エリア--> <tr> <th class="active">誕生日</th> <td> <div class="form-group" th:classappend="${#fields.hasErrors('birthday')}?'has-error'"> <input type="text" class="form-control" placeholder="yyyy/MM/dd" th:field="*{birthday}"/> <span class="textt-danger" th:if="${#fields.hasErrors('birthday')}" th:errors="*{birthday}"> birthday error</span> </div> </td> </tr> <!-- 年齢の入力エリア--> <tr> <th class="active">年齢</th> <td> <div class="form-group" th:classappend="${#fields/hasErrors('age')} ? 'has-error'"> <input type="text" class="form-control" th:field="*{age}"/> <span class="text-danger" th:if="${#fields.hasErrors('age')}" th:errors="*{age}"> age error</span> </div> </td> </tr> <!-- 結婚ステータスの入力エリア--> <tr> <th class="active">結婚</th> <td> <div class="form-group"> <!-- ポイント:ラジオボタンの実践--> <div th:each="item:${radioMarriage}"> <input type="radio" name="radioMarrige" th:text="${item.key}" th:value="${item.value}" th:field="*{marriage}"> </div> <span class="text-danger" th:if="${#fields.hasErrors('marriage')}" th:errors="*{marriage}"> marriage error</span> </div> </td> </tr> </table> <!-- エラーメッセージの一覧表示 --> <ul> <li th:each="error:${#fields.detailedErrors()}"> <span th:text="${error.message}">Error message</span> </li> </ul> <!-- ユーザー登録ボタン--> <button class="btn btn-primary" type="submit">ユーザー登録</button> </form> </div> </body> </html>あなたの回答
tips
プレビュー