Java Thymeleaf 模板解析错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/29750231/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Thymeleaf template parsing error
提问by tarexgg
I get parsing error when I try to load localhost:8080/
.
当我尝试加载localhost:8080/
.
I can't find any errors in my template, so why have I this mistake?
我在模板中找不到任何错误,为什么我会出现这个错误?
Error
错误
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Mon Apr 20 16:59:56 EEST 2015
There was an unexpected error (type=Internal Server Error, status=500).
Exception parsing document: template="index", line 26 - column 3
Template (HTML)
模板 (HTML)
<tr th:each="customer : ${customers}">
<td th:text="${customer.identity}">001</td>
<td th:text="${customer.name}">Name</td>
<td th:text="${customer.address}">Address</td>
<td th:text="${customer.age}">Age</td>
</tr>
View (Class)
查看(类)
public String mainPage(Model model){
ApplicationContext context = new ClassPathXmlApplicationContext("beans.xml");
PersonJDBCTemplate personJDBCTemplate = (PersonJDBCTemplate) context.getBean("personJDBCTemplate");
List<Person> persons = personJDBCTemplate.getAllPersons();
model.addAttribute("customers", persons);
return "index";
}
采纳答案by Faraj Farook
May beyou are missing a closing tagsomewhere. I have no idea what you have in the HTML template, unless you post the complete code.
可能是您在某处缺少结束标记。我不知道你在 HTML 模板中有什么,除非你发布完整的代码。
But replace your current file with this template. And it should work. Then you can add your missing codes to it.
但是用这个模板替换你当前的文件。它应该工作。然后,您可以将丢失的代码添加到其中。
<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head lang="en"></head>
<body>
<tr th:each="customer : ${customers}">
<td th:text="${customer.identity}">001</td>
<td th:text="${customer.name}">Name</td>
<td th:text="${customer.address}">Address</td>
<td th:text="${customer.age}">Age</td>
</tr>
</body>
</html>
回答by Brian Risk
Your template name may be misspelled!
您的模板名称可能拼错了!
This just bit me in the butt. All closing tags were verified via online tool, but that won't help you when the template engine name you define in your controller doesn't exactly match with the actual file name.
这只是咬我的屁股。所有结束标记都通过在线工具进行了验证,但是当您在控制器中定义的模板引擎名称与实际文件名不完全匹配时,这对您无济于事。
Notethat this answer addresses a possible, but not highly probable explanation for the error. It is more for people coming in from search; the specific reasons that lead the OP to post are most likely caused by the lack of closing tag. However, who knows? The controller code was not included.
请注意,此答案解决了对错误的可能但不太可能的解释。更适合从搜索进来的人;导致 OP 发布的具体原因很可能是由于缺少结束标记造成的。然而,谁知道呢?控制器代码不包括在内。