2

在 Apache Tiles 站点的与 FreeMarker 集成页面上,它具有:

To access ".ftl" files as attributes, register FreeMarkerAttributeRenderer this way (only available in a servlet environment):

@Override
protected void registerAttributeRenderers(
        BasicRendererFactory rendererFactory, TilesApplicationContext applicationContext,
        TilesRequestContextFactory contextFactory,
        TilesContainer container, AttributeEvaluator evaluator) {
    super.registerAttributeRenderers(rendererFactory, applicationContext, contextFactory,
            container, evaluator);
    FreeMarkerAttributeRenderer freemarkerRenderer = new FreeMarkerAttributeRenderer();
    freemarkerRenderer.setApplicationContext(applicationContext);
    freemarkerRenderer.setEvaluator(evaluator);
    freemarkerRenderer.setRequestContextFactory(contextFactory);
    freemarkerRenderer.setParameter("TemplatePath", "/");
    freemarkerRenderer.setParameter("NoCache", "true");
    freemarkerRenderer.setParameter("ContentType", "text/html");
    freemarkerRenderer.setParameter("template_update_delay", "0");
    freemarkerRenderer.setParameter("default_encoding", "ISO-8859-1");
    freemarkerRenderer.setParameter("number_format", "0.##########");
    freemarkerRenderer.commit();
    rendererFactory.registerRenderer("freemarker", freemarkerRenderer);
}

但我不知道我把这段代码放在哪里。您注册此代码的正常位置是什么/我应该扩展和覆盖哪个类?谢谢你的帮助。

4

2 回答 2

1

你好,我刚刚想通了

在此处输入图像描述

这是我的项目herichy,我使用基于java的配置,webconfig就像web.xml

    @Bean
public TilesConfigurer tilesConfigurer() {
    TilesConfigurer tilesConfigurer = new TilesConfigurer();
    tilesConfigurer.setDefinitions("/WEB-INF/views/tiles/tiles.xml");
    tilesConfigurer.setCheckRefresh(true);
    tilesConfigurer.setTilesInitializer(new pringCompleteAutoloadTilesInitializer());
    return tilesConfigurer;
}

注意tilesConfigurer.setTilesInitializer(new pringCompleteAutoloadTilesInitializer());

这是 SpringCompleteAutoloadTilesInitializer

public class SpringCompleteAutoloadTilesInitializer extends    CompleteAutoloadTilesInitializer
{
    @Override
    protected AbstractTilesContainerFactory   createContainerFactory(ApplicationContext context)
    {
        return new SpringCompleteAutoloadTilesContainerFactory();
    }
}

并且 SpringCompleteAutoloadTilesContainerFactory 是您想要放置代码的地方

在此处输入图像描述

你可以在这里查看我的项目git project

于 2017-03-23T14:42:22.120 回答
0

此代码进入您的 TilesContainerFactory 实现。

(通常扩展 BasicTilesContainerFactory)。

于 2013-09-15T13:36:35.843 回答