无法使用th:object在Spring Boot中加载页面

时间:2019-11-20 09:29:34

标签: spring-boot thymeleaf

它包含一行错误:“模板解析期间发生错误(模板:“类路径资源[templates // register.html]””)”。 我无法打开注册html页面以将新对象添加到db中。为什么?

from django.urls.exceptions import Resolver404
from django.urls.resolvers import get_resolver

def pattern_after_admin(request):
    """
    Returns True if the request URL matches a pattern listed
    after the `/admin/` pattern or no pattern at all.
    """
    resolver = get_resolver()
    after_admin = False
    for pattern in resolver.url_patterns:
        try:
            pattern.resolve(request.path)
        except Resolver404:
            try:
                pattern.resolve('/admin/')
            except Resolver404:
                pass
            else:
                after_admin = True
                break
        else:
            break
    return after_admin

我的控制器

<form th:action="@{/register-user}" th:object="user" method="post">
        <div class="form-group">
            <label for="email">Email:</label>
            <input type="email" class="form-control" id="email" placeholder="Enter email" name="email">
        </div>
        <div class="form-group">
            <label for="password">Password:</label>
            <input type="password" class="form-control" id="password" placeholder="Enter password" name="pswd">
        </div>
        <div class="form-group form-check">
        </div>
        <button type="submit" class="btn btn-primary">Register</button>
    </form>

1 个答案:

答案 0 :(得分:1)

您的“用户”是模型属性,因此,要使用th:object语法来访问它(并将其用作${...})。结果将如下所示:

<form th:action="@{/register-user}" th:object="${user}" method="post">