我無法讓 th:replace 作業,這是我的百里香葉:
<div th:replace="${#authorization.expression('hasRole(''ROLE'')') ? 'fragments/first :: content(content=${content})' : 'fragments/second :: content(content=${content})'}"></div>
如果我轉到此頁面,我會收到此錯誤:
Error resolving template [${#authorization.expression('hasRole(''ROLE'')') ? 'fragments/upgradeblock], template might not exist or might not be accessible by any of the configured Template Resolvers (template: "fragments/first" - line 36, col 34)
我想我必須更改 Thymeleaf 代碼中的某些內容,但不知道是什么。謝謝您的幫助
uj5u.com熱心網友回復:
似乎正確的語法應該如下所示:
<div th:replace="${#authorization.expression('hasRole(''ROLE'')')} ? ~{fragments/first :: content(content=${content})} : ~{fragments/second :: content(content=${content})}"></div>
更進一步,這種語法也適用于我:
<div th:replace="~{${'fragments/' (#authorization.expression('hasRole(''ROLE'')') ? 'first' : 'second')} :: content(content=${content})}"></div>
uj5u.com熱心網友回復:
也許你可以像這樣拆分它:
<th:block th:if="${#authorization.expression('hasRole(''ROLE'')')}">
<div th:replace="fragments/first :: content(content=${content})"></div>
</th:block>
<th:block th:unless="${#authorization.expression('hasRole(''ROLE'')')}">
<div th:replace="fragments/second :: content(content=${content})"></div>
</th:block>
請注意,它無法通過合并來實作<th:block>與<div>因屬性優先的th:replace是更高的。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/409044.html
標籤:
上一篇:問:事務代碼為什么這么好用?
