繁体   English   中英

Thymeleaf 模板解析错误

[英]Thymeleaf template parsing error

当我尝试加载localhost:8080/时出现解析错误。

我在模板中找不到任何错误,为什么我会出现这个错误?

错误

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

模板 (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>

查看(类)

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";
}

可能是您在某处缺少结束标记 我不知道你在 HTML 模板中有什么,除非你发布完整的代码。

但是用这个模板替换你当前的文件。 它应该工作。 然后,您可以将丢失的代码添加到其中。

<!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>

您的模板名称可能拼错了!

这只是咬我的屁股。 所有结束标记都通过在线工具进行了验证,但是当您在控制器中定义的模板引擎名称与实际文件名不完全匹配时,这对您无济于事。

请注意,此答案解决了对错误的可能但不太可能的解释。 更适合从搜索进来的人; 导致 OP 发布的具体原因很可能是由于缺少结束标记造成的。 然而,谁知道呢? 控制器代码不包括在内。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM