【问题标题】:Spring Boot message.properties Question: How to send value to the fragment?Spring Boot message.properties 问题:如何向片段发送值?
【发布时间】:2022-01-24 13:58:41
【问题描述】:

我在将来自 message.properties 文件的值发送到 thymeleaf 片段页面时遇到问题。 在我将 message.properites 文件中的值定义为 "brand.name" 后,我想将其发送到该页面,但我无法处理。

即使我可以使用column_link('name',[[#{brand.name}]],'none')"column_link('name',#{brand.name},'none')",我也无法在片段中显示名称。

我该怎么做?

这是我的 message_en.properties 文件,如下所示。

...
brand.name = Brand Name:
...

这是我的 HTML 页面,如下所示。

...
<th th:replace="fragments :: column_link('name','Brand Name','none')" />
...

这是我的片段页面,如下所示。

<th th:fragment="column_link(fieldName, columnLabel, removeTag)" th:remove="${removeTag}">
    
        <a class="text-white"
            th:href="@{${moduleURL} + '/page/' + ${currentPage} + '?sortField=' + ${fieldName}  +'&sortDir=' + ${sortField != fieldName ? sortDir : reverseSortDir} + ${keyword != null ? '&keyword=' + keyword : ''}">
            [[${columnLabel}]]
        </a>                                
        <span th:if="${sortField == fieldName}"
            th:class="${sortDir == 'asc' ? 'fas fa-sort-up' : 'fas fa-sort-down'}" ></span> 
                            
</th>

【问题讨论】:

    标签: java spring-boot properties thymeleaf


    【解决方案1】:

    你应该能够像这样传递一个属性:

    <th th:replace="fragments :: column_link('name',#{brand.name},'none')" />
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-10-11
      • 1970-01-01
      • 1970-01-01
      • 2020-11-13
      • 2020-09-22
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多