gpt4 book ai didi

java - 如何在 Apache Tiles 中注册属性渲染器?

转载 作者:行者123 更新时间:2023-11-30 11:28:47 24 4
gpt4 key购买 nike

在 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);
}

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

最佳答案

你好,我刚刚想通了

enter image description here

这是我的项目继承,我使用基于 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 就是您要放置代码的地方

enter image description here

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

关于java - 如何在 Apache Tiles 中注册属性渲染器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18771120/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com