当我使用th:field时,百里香th:field返回错误

时间:2019-02-08 01:07:53

标签: spring spring-boot spring-mvc thymeleaf

当我使用这样的输入时,我没有问题:

<input type="text" name="title" />

但是,如果我将th:name放在该位置,则会出现错误500:

<input type="text" th:field="${title}"/> 

来吧tomar erro 500,符合abaixo

这是git储存库:https://github.com/getJv/springStudy

这是错误:

Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.

Thu Feb 07 23:03:56 BRST 2019
There was an unexpected error (type=Internal Server Error, status=500).
An error happened during template parsing (template: "class path resource [templates/books/form.html]")
org.thymeleaf.exceptions.TemplateInputException: An error happened during template parsing (template: "class path resource [templates/books/form.html]")

1 个答案:

答案 0 :(得分:0)

在此处参考Thymeleaf Documentation

th:field 用于与带有上下文变量的 th:object 配对时自动填充值。

如果您想动态呈现标签的名称,则应改用 th:name


下面的示例将“ Winnie the Pooh”作为值显示

BookController.java

Book book = new Book();
book.setTitle("Winnie the Pooh");

ModelAndView mv = new ModelAndView("book/form");
mv.addObject("book", book);

胸腺:

<form th:object="${book}">
    <input type="text" th:field="*{title}">
</form>