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

rat*_*lan 2 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>
Run Code Online (Sandbox Code Playgroud)

这将引发org.thymeleaf.exceptions.TemplateProcessingException:无法解析为分配序列:“ x = $ {thumbx},xlink:href = $ {thumbfile}”。

关于如何设置属性xlink:href的任何想法?

Nic*_*las 5

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

<image th:attr="x=${thumbx},'xlink:href'=${thumbfile}" />
Run Code Online (Sandbox Code Playgroud)