Thymeleaf 显示具有动态列数的表格

Joh*_*din 5 java thymeleaf spring-boot

我正在使用 thymeleaf 作为模板引擎开发 Spring Boot 应用程序。我有这种情况,我需要显示一个列数可能不同的列。这是我到目前为止所拥有的:

<table class="table table-hover" th:if="${d.hasRecords()}">
    <thead>
        <tr> 
            <th:block th:eacth="h : ${d.header}">
                <th th:colspan="${d.header.length}" th:text="${h}">Header Field</th>
            </th:block>
        </tr>
    </thead>
    <tbody>
        <tr th:each="record : ${d.records}">
            <th:block th:each="field : ${record}">
                <td th:text="${field}">Dataset Field</td>
            </th:block>
        </tr>
    </tbody>
</table>
Run Code Online (Sandbox Code Playgroud)

变量header是标准 String[] 数组,而records对象是字符串数组列表。该表显示表正文,但不显示表头。唯一的区别(据我所知)是主体是嵌套循环,而标题不是。有人可以帮我解释一下为什么标题不会显示吗?并且头数组不为空或者null

Joh*_*din 1

就像 @holmis83 提到的那样,这是一个拼写错误。尴尬吗?是的