Thymeleaf:使用命名空间设置属性
Thymeleaf: Setting attributes with namespace
在 Spring 引导应用程序中,我尝试设置一个带有命名空间的属性。这是我尝试过的:
<svg id="svg1" width="100%" viewBox="0 0 400 100" xmlns="http://www.w3.org/2000/svg"
xmlns:th="http://www.thymeleaf.org"
xmlns:xlink="http://www.w3.org/1999/xlink">
...
<image th:attr="x=${thumbx},xlink:href=${thumbfile}"
x="150" y="50" width="20" height="20"
xlink:href="http://s3.amazonaws.com/some.png"/>
...
</svg>
引发 org.thymeleaf.exceptions.TemplateProcessingException:无法解析为赋值序列:"x=${thumbx},xlink:href=${thumbfile}"。
关于如何设置属性的任何想法xlink:href?
尝试用简单的引号将属性名称括起来:
<image th:attr="x=${thumbx},'xlink:href'=${thumbfile}" />
对于图标,bootstrap 工作正常
<svg class="bi" width="1em" height="1em" fill="currentColor">
<use th:attr="'xlink:href'=@{/image/bootstrap-icons.svg#download}"></use>
</svg>
在 Spring 引导应用程序中,我尝试设置一个带有命名空间的属性。这是我尝试过的:
<svg id="svg1" width="100%" viewBox="0 0 400 100" xmlns="http://www.w3.org/2000/svg"
xmlns:th="http://www.thymeleaf.org"
xmlns:xlink="http://www.w3.org/1999/xlink">
...
<image th:attr="x=${thumbx},xlink:href=${thumbfile}"
x="150" y="50" width="20" height="20"
xlink:href="http://s3.amazonaws.com/some.png"/>
...
</svg>
引发 org.thymeleaf.exceptions.TemplateProcessingException:无法解析为赋值序列:"x=${thumbx},xlink:href=${thumbfile}"。
关于如何设置属性的任何想法xlink:href?
尝试用简单的引号将属性名称括起来:
<image th:attr="x=${thumbx},'xlink:href'=${thumbfile}" />
对于图标,bootstrap 工作正常
<svg class="bi" width="1em" height="1em" fill="currentColor">
<use th:attr="'xlink:href'=@{/image/bootstrap-icons.svg#download}"></use>
</svg>