簡體   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