遵循 Freemarker文档
控制器
public ModelAndView home() {
ModelAndView mav = new ModelAndView();
mav.addObject("users", userList);
mav.addObject("user", "Big Joe");
mav.addObject("title", "Testing initial page, using FreeMarker!");
try {
mav.addObject("doc", freemarker.ext.dom.NodeModel.parse (new File("C:\\Users\\Himanshuy\\Desktop\\2.xml")));
} catch (SAXException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ParserConfigurationException e) {
e.printStackTrace();
}
return mav;
}
错误
FreeMarker template error: For "${...}" content: Expected a string or something automatically convertible to string (number, date or boolean), but this evaluated to a sequence+hash (wrapper: f.e.dom.NodeListModel): ==> header [in template "index.ftl" at line 13, column 3
超光速
<#assign header=doc.title >
${header}
XML
<book>
<title>Test Book</title>
<chapter>
<title>Ch1</title>
<para>p1.1</para>
<para>p1.2</para>
<para>p1.3</para>
</chapter>
<chapter>
<title>Ch2</title>
<para>p2.1</para>
<para>p2.2</para>
</chapter>
</book>
我的方法有什么问题?