在我的控制器中,我设置了一个名为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.html
或accountSetting.html
当我执行<h1 th:text="${currentAccountant.name}" /></h1>
时,它不起作用。
如何将对象currentAccountant
传递给标签?
答案 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>