「を含む」レンダリングこのようdoRender呼び出すクラス「AbstractTemplateView」とオーバーライド「renderMergedTemplateModel」方法:春Freemarkerのは、私はそれの内側(page1.ftlとpage2.ftl)が含まとFreeMarkerのテンプレート(index.ftl)を持っている個別
protected void doRender(Map<String, Object> model, String viewName, HttpServletResponse response)
throws Exception {
logger.debug("start doRender");
try {
Configuration config = new Configuration();
String templatePath = templateService.getTemplateLocation();
config.setDirectoryForTemplateLoading(new File(templatePath));
Template template = config.getTemplate(viewName);
response.setContentType("text/html; charset=" + template.getEncoding());
PrintWriter out = response.getWriter();
template.process(model, out);
} catch (IOException e) {
String message = format("cannot render template <{0}> due to IOException: {1}", e.getMessage());
logger.error(message, e);
throw new NestedServletException(message, e);
}
}
私の質問は、私はpage1.ftlとpage2.ftlごとに個別に含まれるディレクトリを設定する方法、ありますか?出来ますか ? "setDirectoryForTemplateLoading"メソッドは、テンプレートのデフォルトディレクトリのみを設定します。インクルードはこのディレクトリに対して相対的に検索されます。
この問題の背景は、インクルードをロードすることです。しかし、私がインクルードを見つけることができなければ、それは別のディレクトリを探すでしょう。
例FTLは(index.ftlを)言う:
FREEMARKER MAIN
<#include "page1.ftl">
<#include "page2.ftl">
私はmultiloaderを試み、それがindex.ftl上で動作しているようです。それはiveが定義したディレクトリに解決しようとします。 page1.ftlとpage2.ftlの異なるディレクトリパスのように解決するにはどうすればよいですか?出来ますか?インクルードの1つが存在しない場合、エラーが発生します。
その一部が取り組んでいます。 – Arlandria