当我像这样使用输入时,我没有问题:
<input type="text" name="title" />
但是如果我把 th:name 放在那个地方,我得到一个错误 500:
<input type="text" th:field="${title}"/>
Começo a tomar erro 500, conforme 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]")
请参阅此处的百里香叶文档
th:field 用于在与 th:object 与上下文变量配对时自动填充值。
如果要动态呈现标签的名称,则应改用 th:name
下面的示例将显示"小熊维尼"作为值
图书控制器.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>