Freemarker的:
如果我的数据是:
x = [{
name= satyajit,
company = hewlett & packard
}, {
name= akanksha,
company = google & co
}]
以下是我想如何访问ftl模板中的上述列表。
${x}
但是,上面的代码会抛出一个错误:实体名称必须紧跟'&'在实体参考中。
有没有办法逃脱'&'在数据中,如'&'在' hewlett&帕卡德'来自freemarker模板中的webservice数据?
编辑:
面临错误:
[Fatal Error] NewFile.xml:27:57: The entity name must immediately follow the '&' in the entity reference.
Exception in thread "main" org.xml.sax.SAXParseException; systemId: file:/D:/NewFile.xml; lineNumber: 27; columnNumber: 57; The entity name must immediately follow the '&' in the entity reference.
at org.apache.xerces.parsers.DOMParser.parse(Unknown Source)
at org.apache.xerces.jaxp.DocumentBuilderImpl.parse(Unknown Source)
at javax.xml.parsers.DocumentBuilder.parse(Unknown Source)
答案 0 :(得分:1)
将< #escape x中的文本块换成x?html>指令。
public static final String ESCAPE_PREFIX = "<#ftl strip_whitespace=true><#escape x as x?html>";
public static final String ESCAPE_SUFFIX = "</#escape>";
ESCAPE_PREFIX + templateText + ESCAPE_SUFFIX
参见:http://freemarker.org/docs/dgui_misc_autoescaping.html
http://watchitlater.com/blog/2011/10/default-html-escape-using-freemarker/
答案 1 :(得分:0)
搜索了一段时间后,我发现内置html的freemarker可以解决我的问题。就我而言:
${x?html}