Thymeleaf:使用命名空间设置属性

时间:2016-02-27 17:28:46

标签: thymeleaf

在Spring Boot应用程序中,我尝试使用命名空间设置属性。这就是我的尝试:

<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:无法解析为赋值序列:&#34; x = $ {thumbx},xlink:href = $ {thumbfile}&#34;。

有关如何设置属性xlink:href?

的任何想法

2 个答案:

答案 0 :(得分:4)

尝试用简单的引号包装属性名称:

<image th:attr="x=${thumbx},'xlink:href'=${thumbfile}" />

答案 1 :(得分:0)

对于图标,引导程序可以正常工作

<svg class="bi" width="1em" height="1em" fill="currentColor">
    <use  th:attr="'xlink:href'=@{/image/bootstrap-icons.svg#download}"></use>
</svg>
相关问题