我創建了一個Thymeleaf片段,我在所有的視圖狀態中都包含視圖。如何通過SpEL中的枚舉值訪問內聯映射的值?
<th:block th:fragment="flow-messages"
th:with="alertTypes = ${ {'INFO':'alert-info','ERROR':'alert-error','WARNING':'alert-warning'} }">
<div
class="alert"
th:each="message: ${flowRequestContext.messageContext.allMessages}"
th:classappend="${alertTypes.get(message.severity)}">
<p th:text="${message.text}">Message text</p>
</div>
</th:block>
正如你可以在上面看到,我初始化嚴重性級別(org.springframework.binding.message.Severity)和相關引導類的地圖。
問題是,alertTypes.get(message.severity)不起作用(返回一個空值)。我無法添加相應的類。
任何人都知道我該如何解決這個問題?
alertTypes是您的項目的枚舉?你可以發佈代碼嗎? – rptmat57
alertTypes在th:with上定義。 th:with =「alertTypes = $ {{'INFO':'alert-info','ERROR':'alert-error','WARNING':'alert-warning'}}」 –
@SergioSánchezSanchez你確認了這個值message.severity是正確的?我檢查了地圖工作正常,順便說一句是警報 - 危險不錯誤 – cralfaro