当我使用这样的输入时,我没有问题:
<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]")
答案 0 :(得分:0)
th:field 用于与带有上下文变量的 th:object 配对时自动填充值。
如果您想动态呈现标签的名称,则应改用 th:name
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>