Java 下载属性

Java 下载属性,java,html,thymeleaf,Java,Html,Thymeleaf,在my Thymeleaf模板中,我能够将Java映射内容处理为html,如下所示: <div th:each="file : ${files}"> <span th:text="${file.key}"></span> <!-- here file.key is readed --> ---- </div> <a th:download="${file.key}" href="...ok..."> D

在my Thymeleaf模板中,我能够将Java映射内容处理为html,如下所示:

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

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

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

但是服务器上未处理th:download属性,生成的html如下所示:

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


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

如果要设置任意属性的值(不仅仅是Thymeleaf支持的属性),则可以使用
th:attr
。(). 例如:


在Thymeleaf的当前版本(3.0.11)中,是
th:download
属性支持。安德鲁的解决方案现在没有必要了