【问题标题】:Thymeleaf download attributeThymeleaf 下载属性
【发布时间】:2020-06-04 16:10:23
【问题描述】:

在我的 Thymeleaf 模板中,我可以像这样将 Java-map 内容处理为 html:

<div th:each="file : ${files}">
     <span th:text="${file.key}"></span> <!-- here file.key is readed -->
     ----
</div>

然后我尝试添加指定下载文件名称的html download 属性:

<a th:href="..." th:download="${file.key}" > Download </a>

但是th:download属性没有在服务器上处理,生成的html是这样的:

<a th:download="${file.key}" href="...ok..."> Download </a>

如何访问 file.key 属性并将其添加到下载属性?

【问题讨论】:

    标签: java html thymeleaf


    【解决方案1】:

    如果你想设置任意属性的值(不仅仅是 Thymeleaf 支持的),那么你可以使用th:attr。 (Documentation)。例如:

    <a th:href="..." th:attr="download=${file.key}" > Download </a>
    

    【讨论】:

      【解决方案2】:

      Thymeleaf 的当前版本 (3.0.11) 支持 th:download 属性。现在不需要 Andrew 的解决方案。

      【讨论】:

        猜你喜欢
        • 2014-03-15
        • 2017-04-12
        • 1970-01-01
        • 1970-01-01
        • 2020-09-06
        • 2013-10-04
        • 2017-10-06
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多