属性th:此处不允许每个属性(Thymeleaf模板错误)

时间:2018-07-15 20:42:47

标签: spring spring-boot thymeleaf

我创建了一个应用程序,用于在数据库中存储有关狗的信息,同时在项目中运行创建的表,但狗的信息并未更新。

在html文件下面运行该错误

以下代码不起作用

<html lang="en">
<head>
    <!-- META SECTION -->
    <title>Dog Rescue</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <!-- END META SECTION -->
    <!--  BEGIN STYLE -->
    <style>
        table, th, td {
            border: 1px solid black;
            padding: 1px;
        }
    </style>
    <!--  END STYLE -->

</head>
<body>
<h2>Current Dogs In Rescue</h2>
<table>
    <thead>
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Rescue Date</th>
        <th>Vaccinated</th>
    </tr>
    </thead>
    <tbody>
    <tr th:each="dogs : ${dogs}">
        <td th:text="${dogs.id}">Text ...</td>
        <td th:text="${dogs.name}">Text ...</td>
        <td th:text="${dogs.rescued}">Text ...</td>
        <td th:text="${dogs.vaccinated}">Text...</td>
    </tr>
    </tbody>
</table>
</div>

<h2>Add A Dog</h2>
<form action="#" th:action="@{/}" method="post">
    <label>Name<input type="text" name="name" id="name"></input></label>
    <label>Vaccinated<input type="text" name="vaccinated" id="vaccinated"></input></label>
    <label>Rescued<input type="text" name="rescued" id="rescued"></input></label>
    <input type="submit" value="Submit"></input>
</form>
</body>
</html>

html文件未获取信息。 请帮助我 整个项目位于 https://github.com/arulsuju/DogRescue.git

1 个答案:

答案 0 :(得分:3)

您要使用与列表变量相同的变量名() ,请考虑为迭代变量使用不同的名称,例如( dog ),因此代码应为:

<tr th:each="dog : ${dogs}">
    <td th:text="${dog.id}">Text ...</td>
    <td th:text="${dog.name}">Text ...</td>
    <td th:text="${dog.rescued}">Text ...</td>
    <td th:text="${dog.vaccinated}">Text...</td>
</tr>
相关问题