JavaのWebアプリケーション開発フレームワークによる、Webサイト開発の顛末記です。

EclipseのMavenを使った、Spring-MVC、Thymeleaf、MyBatis 等のプログラミングテクニックを、
備忘録的に記録しています。実際に動くソースコードを多用して説明していますので、
これからEclipseや、Spring-MVCを始めたいと思っている人にとって、少しでも参考になれば幸いです。
Spring-MVCの散歩道 > Spring Boot の小径 > 第4歩 Spring Boot 匍匐前進 > 入力チェック

<!DOCTYPE html>

<!-- xmlnsは、Thymeleafのおまじないです -->
<html xmlns:th="http://www.thymeleaf.org">
<head>
<title>Spring-MVCデータモデルの入力チェックサンプル</title>
<meta charset="UTF-8" />
</head>

<body>
<form action="./promenaderes" method="post">
<!-- FormBean(PromenadeFormData)を取り出す -->
<table th:object="${PromenadeFormData}">
    <tr>
        <td>
            あなたのお名前は? <input type="text" th:field="*{myname}" size="40" maxlength="40"/> 
            <!-- 入力検証エラー時のメッセージ表示領域 -->
            <span style="color:red;" th:if="${#fields.hasErrors('myname')}" th:errors="*{myname}">おいらは、すぷりんぐ太郎たじょ</span>
        </td>
    </tr>
    <tr>
        <td>
            あなたの年齢は? <input type="text" th:field="*{age}" size="10" maxlength="3"/> 
            <!-- 入力検証エラー時のメッセージ表示領域 -->
            <span style="color:red;" th:if="${#fields.hasErrors('age')}" th:errors="*{age}">教えてあげない</span>
        </td>
    </tr>
    <tr>
        <td>
            あなたの電話番号は? <input type="text" th:field="*{phone}" size="40" /> 
            <!-- 入力検証エラー時のメッセージ表示領域 -->
            <span style="color:red;" th:if="${#fields.hasErrors('phone')}" th:errors="*{phone}">教えてあげない</span>
        </td>
    </tr>
    <tr>
        <td>
            あなたのemailは? <input type="text" th:field="*{email}" size="60" /> 
            <!-- 入力検証エラー時のメッセージ表示領域 -->
            <span style="color:red;" th:if="${#fields.hasErrors('email')}" th:errors="*{email}">email</span>
        </td>
    </tr>
    <tr>
        <td>
            どれか好きなの選んでね? 
            <input type="radio" th:field="*{checkVals}" value="酒"/>酒 
            <input type="radio" th:field="*{checkVals}" value="博打"/>博打 
            <input type="radio" th:field="*{checkVals}" value="女"/>女 
            <!-- 入力検証エラー時のメッセージ表示領域 -->
            <span style="color:red;" th:if="${#fields.hasErrors('checkValsSelect')}" th:errors="*{checkValsSelect}">どれか選ばんか~ぃ!</span>
        </td>
    </tr>
    <tr>
        <td>
            <input type="submit" value="回答しちゃるけん" />
        </td>
    </tr>
</table>
</form>

</body>
</html>