0

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

FTL

<#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>  

私のアプローチの何が問題になっていますか?

4

2 に答える 2

0

ftl で ${header} を使用するべきではないと思います。xml ファイルの使用方法の例については、このページを参照してください: http://freemarker.org/docs/xgui_imperative_learn.html

于 2013-07-15T18:55:54.323 に答える