春季百里香叶异常解析文档



错误消息如下:

出现意外错误(类型=内部服务器错误, 状态 = 500(。异常解析文档:template="register",第 15 行 - 第3栏

如果我删除使用th:的表单,那么它会正确显示页面。但是通过表格,我得到了错误。我在代码中看不到任何错误,希望有人看一看。

注册.html:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <title>User Registration</title>
</head>
<body>
<h3>User Registration</h3>
<form action="#" th:action="@{/user/register}" th:object="${user}" method="post">
    <p>First Name:</p> <input type="text" th:field="*{firstname}">
    <p>Last Name:</p> <input type="text" th:field="*{lastname}">
    <p>Password:</p> <input type="text" th:field="*{password}">
    <input type="submit" value="Register">
</form>
</body>
</html>

用户控制器.java:

package com.demo.spring.controller;
import com.demo.spring.domain.User;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@Controller
@RequestMapping(value = "/user")
public class UserController {
    @RequestMapping(value = "/register", method = RequestMethod.GET)
    public String registerView(Model model)
    {
        User user = new User();
        model.addAttribute("user", user);
        return "register";
    }
}

用户.java:

package com.demo.spring.domain;
public class User {
    String firstname;
    String lastname;
    String password;
    public String getFirstname() {
        return firstname;
    }
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }
    public String getLastname() {
        return lastname;
    }
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

}

这是因为您错过了<input>元素的结束标记。

例如:使用这个

<input type="text" th:field="*{firstname}"/>

而不是

 <input type="text" th:field="*{firstname}">

Thymeleaf只能处理有效的XML .it 仅适用于格式正确的 XML,因此如果要使用模板模式HTML5您的 HTML 必须是格式正确的 XML。否则,您可以使用LEGACYHTML5模板

最新更新