包括在另一个里面的themleaf模板div

时间:2017-09-22 10:28:17

标签: java spring-mvc thymeleaf

我写了一个thymleaf div,我希望将其包含在另一个thymleaf模板页面中。

但是我得到了这个错误:org.thymeleaf.exceptions.TemplateInputException:解析模板“fragment / pagination”时出错,模板可能不存在或任何配置的模板解析器(managetasks)可能无法访问

以下是主页面代码

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

    <body>
    <table width="100%" class="table table-striped table-bordered table-hover" id="dataTables">
        <thead>
        <tr>
            <th>ID</th>
            <th>Type</th>
            <th>Instance</th>
            <th>Status</th>
            <th>Options</th>
        </tr>
        </thead>
        <tbody>
        <tr data-task-id="" th:each="task : ${tasks}" th:attr="data-task-id=${task.id}">
            <td data-column="taskId" th:text="${task.id}">1123</td>
            <td th:text="${task.task.taskType}"></td>                       
            <td th:text="${task.instance.name}">192.168.100.5</td>
            <td th:text="${task.status}">Done</td>
            <td><button class="btn btn-info infoButton" data-toggle="model" th:attr="data-target='#taskDetailModel'+${task.id}">Detail</button></td>
        </tr>
        </tbody>
    </table>
    <!-- Pagination Bar -->
    <div th:replace="fragments/pagination::paginationbar"></div>
</body>
</html>

以及我想要包含的页面div如下所示:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div th:fragment="paginationbar">
    <div>
        <ul class='pagination pagination-centered'>
            <li th:class="${page.firstPage}?'disabled':''">
                <span th:if='${page.firstPage}'>← First</span>
                <a th:if='${not page.firstPage}' th:href='@{${page.url}(page=0,size=${page.size})}'>← First</a>
            </li>
            <li th:class="${page.hasPreviousPage}? '' : 'disabled'">
                <span th:if='${not page.hasPreviousPage}'>«</span>
                <a th:if='${page.hasPreviousPage}' th:href='@{${page.url}(page=${page.number-2},size=${page.size})}' title='Go to previous page'>«</a>
            </li>
            <li th:each='item : ${page.items}' th:class="${item.current}? 'active' : ''">
                <span th:if='${item.current}' th:text='${item.number}'>1</span>
                <a th:if='${not item.current}' th:href='@{${page.url}(page=${item.number-1},size=${page.size})}'><span th:text='${item.number}'>1</span></a>
            </li>
            <li th:class="${page.hasNextPage}? '' : 'disabled'">
                <span th:if='${not page.hasNextPage}'>»</span>
                <a th:if='${page.hasNextPage}' th:href='@{${page.url}(page=${page.number},size=${page.size})}' title='Go to next page'>»</a>
            </li>
            <li th:class="${page.lastPage}? 'disabled' : ''">
                <span th:if='${page.lastPage}'>Last →</span>
                <a th:if='${not page.lastPage}' th:href='@{${page.url}(page=${page.totalPages - 1},size=${page.size})}'>Last →</a>
            </li>
        </ul>
    </div>
</div>
</body>
</html>

1 个答案:

答案 0 :(得分:0)

问题解决了我在

中提供了错误的文件夹名称
<div th:replace="fragments/pagination::paginationbar"></div>

文件夹名称是fargments而不是片段,所以代码中没有错误