2016-02-27 87 views
1

在Spring Boot應用程序中,我嘗試使用命名空間設置屬性。下面是我的嘗試:Thymeleaf:使用命名空間設置屬性

<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的任何想法?

回答

4

嘗試用簡單的引號包裹屬性名稱:

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

就是這樣,謝謝! – ratlan