为什么我不能送模特? Spring Boot 2 - Thymeleaf

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了为什么我不能送模特? Spring Boot 2 - Thymeleaf相关的知识,希望对你有一定的参考价值。

我无法打开注册页面。如果我删除th:显示字段页面。我该如何解决问题。我不会说英语,谢谢...

错误

 Whitelabel Error Page
    This application has no explicit mapping for /error, so you are seeing this as a fallback.
    Thu Mar 01 01:10:34 EET 2018
    There was an unexpected error (type=Internal Server Error, status=500).
    An error happened during template parsing (template: "class path resource [templates/register.html]")

例外

org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/register.html]")

注册HTML

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<h3>Register</h3>
<form th:action="@{register}" method="post" th:object="${user}">

<input type="text"  th:field="*{username}">
<input type="text"  th:field="*{password}">
<input type="submit" value="Submit">
</form>
 </body>
</html>

调节器

@Controller
@RequestMapping("/")
public class UserController {

    @RequestMapping(value="", method=RequestMethod.GET)
    public String getHomePage()
    {
        return "home";
    }

    @RequestMapping(value="register",method=RequestMethod.GET)
    public String getRegisterPage(Model model)
    {
        model.addAttribute("user",new User());
        return "register";
    }

}
答案

关闭所有输入标签并尝试th:action="@{/register}"

以上是关于为什么我不能送模特? Spring Boot 2 - Thymeleaf的主要内容,如果未能解决你的问题,请参考以下文章

五本Spring Boot书籍花落谁家?

Spring/Spring-Boot 学习2 入门知识

为啥 DataSource 不能在 Spring Boot 应用程序中自动装配?

在 Spring Security 5 OAuth Client 和 Spring Boot 2.0 中,authorizationGrantType 不能为空

Spring boot 3问题:为什么不能使用Postman和Frontend调用API调用API,然后得到空数组?

一图看懂Spring Boot 异步框架