spring thymeleaf传递属性到制表符

时间:2018-02-15 12:37:33

标签: java spring thymeleaf

在我的控制器中,我设置了一个名为currentAccount的对象。在当前的main.html中,我可以通过<h1 th:text="${currentAccountant.name}" /></h1>

显示其详细信息

我有标签。标签在主页面中链接如下。

<!-- Tab content refers to this part -->
<div id="tabs-content" class="tab-content">
    <div id="home-tabs" class="tab-pane fade in active">
        <div th:include="fragments/admin/companyProfile::companyProfile">
        </div>
    </div>

    <div id="settings-tabs" class="tab-pane fade">
        <div th:include="fragments/admin/accountSetting::accountSetting">b</div>
    </div>
</div>

companyProfile.htmlaccountSetting.html当我执行<h1 th:text="${currentAccountant.name}" /></h1>时,它不起作用。

如何将对象currentAccountant传递给标签?

1 个答案:

答案 0 :(得分:1)

您正在寻找parameterized fragments。首先对片段进行参数化设置:

<div th:fragment="companyProfile(currentAccountant)"> ...

您可以通过传递所需的参数来应用此片段:

<!-- Tab content refers to this part -->
<div id="tabs-content" class="tab-content">
    <div id="home-tabs" class="tab-pane fade in active">
        <div th:include="fragments/admin/companyProfile::companyProfile(${currentAccount})">
        </div>
    </div>

    <div id="settings-tabs" class="tab-pane fade">
        <div th:include="fragments/admin/accountSetting::accountSetting(${${currentAccount}})">b</div>
    </div>
</div>