Java SpringInputGeneralFieldTagProcessor中的Spring TelemplateProcessingException异常

Java SpringInputGeneralFieldTagProcessor中的Spring TelemplateProcessingException异常,java,spring,spring-boot,thymeleaf,Java,Spring,Spring Boot,Thymeleaf,我在控制器方法中创建: @RequestMapping(value = "/user/registration", method = RequestMethod.GET) public String showRegistrationForm(WebRequest request, Model model) { UserDto userDto = new UserDto(); model.addAttribute("user", userDto);

我在控制器方法中创建:

@RequestMapping(value = "/user/registration", method = RequestMethod.GET)
    public String showRegistrationForm(WebRequest request, Model model) {
        UserDto userDto = new UserDto();
        model.addAttribute("user", userDto);
        return "registration";
    } 
当我转到URL localhost:8080/user/registration SpringInputGeneralFieldTagProcessor时,抛出TemplateProcessingException

org.thymeleaf.exceptions.TemplateProcessingException:运行期间出错 处理器的执行 'org.thymeleaf.spring4.processor.SpringInputGeneralFieldTagProcessor' (模板:“注册”-第12行,第36列)

如何解决这个问题

registration.html

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Registration page</title>
</head>
<body>
<form name='regForm' th:userDto="${user}" th:action="@{/registration}" enctype="utf8" method="post">
    <table>
        <tr>
            <td>User:</td>
            <td><input type="text" th:field="*{username}"/></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type='email' th:field="*{email}"/></td>
        </tr>

        <tr>
            <td>Password:</td>
            <td><input type='password' th:field="*{password}"/></td>
        </tr>
        <tr>
            <td>Matching password:</td>
            <td><input type='password' th:field="*{matchingPassword}"/></td>
        </tr>
        <tr>
            <td><input name="submit" type="submit" value="submit" /></td>
        </tr>

    </table>
</form>

</body>
</html>

因为您使用的是用户,所以应该将用户属性添加到所有属性中

在这里您可以找到工作代码 `


注册页
用户:
电邮:
密码:
匹配密码:
`

将th:userDto=“${user}”替换为th:objet=“${user}”,然后使用th:field=“*{username}”。它很好用。
package com.eve.web.dto;

import com.eve.validation.ValidEmail;
import org.hibernate.validator.constraints.NotEmpty;

import javax.validation.constraints.NotNull;

public class UserDto {
    @NotNull
    @NotEmpty
    private String username;


    @NotNull
    @NotEmpty
    private String password;

    private String matchingPassword;

    @ValidEmail
    @NotNull
    @NotEmpty
    private String email;


    public String getUsername() {
        return username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public String getMatchingPassword() {
        return matchingPassword;
    }

    public void setMatchingPassword(String matchingPassword) {
        this.matchingPassword = matchingPassword;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }
}
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8"/>
    <title>Registration page</title>
</head>
<body>
<form name='regForm' th:userDto="${user}" th:action="@{/registration}" enctype="utf8" method="post">
    <table>
        <tr>
            <td>User:</td>
            <td><input type="text" th:field="*{user.username}"/></td>
        </tr>
        <tr>
            <td>Email:</td>
            <td><input type='email' th:field="*{user.email}"/></td>
        </tr>

        <tr>
            <td>Password:</td>
            <td><input type='password' th:field="*{user.password}"/></td>
        </tr>
        <tr>
            <td>Matching password:</td>
            <td><input type='password' th:field="*{user.matchingPassword}"/></td>
        </tr>
        <tr>
            <td><input name="submit" type="submit" value="submit" /></td>
        </tr>

    </table>
</form>

</body>
</html>