首页 > 解决方案 > 带有小胡子和弹簧错误标签的错误消息

问题描述

我从 Spring 中找到了以下文档来轻松验证表单。 https://github.com/spring-guides/gs-validating-form-input 现在我遇到的问题是无法将 Thymeleaf 错误标签与 Mustache 一起使用。有没有人有解决方案或想法?

这是文档中的解决方案

<html>
    <body>
        <form action="#" th:action="@{/}" th:object="${personForm}" method="post">
            <table>
                <tr>
                    <td>Name:</td>
                    <td><input type="text" th:field="*{name}" /></td>
                    <td th:if="${#fields.hasErrors('name')}" th:errors="*{name}">Name Error</td>
                </tr>
                <tr>
                    <td>Age:</td>
                    <td><input type="text" th:field="*{age}" /></td>
                    <td th:if="${#fields.hasErrors('age')}" th:errors="*{age}">Age Error</td>
                </tr>
                <tr>
                    <td><button type="submit">Submit</button></td>
                </tr>
            </table>
        </form>
    </body>
</html>

我的 edit.mustache 文件的一部分

<form action="/event/save" enctype='multipart/form-data' method="post">
    {{#event}}
        <div class="form-row">
            <div class="form-group col-md-6">
                <label for="title">Name</label>
                <input min="1" maxlength="60" type="text" class="form-control" id="title" name="title"
                       placeholder="Titel" required
                       value="{{title}}">
            </div>
        </div>

标签: spring-bootvalidationspring-mvctagsmustache

解决方案


推荐阅读