84669인 학습
152542인 학습
20005인 학습
5487인 학습
7821인 학습
359900인 학습
3350인 학습
180660인 학습
48569인 학습
18603인 학습
40936인 학습
1549인 학습
1183인 학습
32909인 학습
文章:http://csjava.blog.163.com/bl...
那我用maven怎么下载这个依赖
光阴似箭催人老,日月如移越少年。
See freemarker-template-inheritance
dependencies { compile 'kr.pe.kwonnam.freemarker:freemarker-template-inheritance:0.4.RELEASE' }
@Bean public Map freemarkerLayoutDirectives() { Map freemarkerLayoutDirectives = new HashMap(); freemarkerLayoutDirectives.put("extends", new ExtendsDirective()); freemarkerLayoutDirectives.put("block", new BlockDirective()); freemarkerLayoutDirectives.put("put", new PutDirective()); return freemarkerLayoutDirectives; } @Bean public FreeMarkerConfigurer freemarkerConfig() { FreeMarkerConfigurer freemarkerConfig = new FreeMarkerConfigurer(); freemarkerConfig.setTemplateLoaderPath("/WEB-INF/ftls/"); freemarkerConfig.setDefaultEncoding("UTF-8"); Map freemarkerVariables = new HashMap(); freemarkerVariables.put("layout", freemarkerLayoutDirectives()); freemarkerConfig.setFreemarkerVariables(freemarkerVariables); return freemarkerConfig; } @Bean public ViewResolver viewResolver() { FreeMarkerViewResolver viewResolver = new FreeMarkerViewResolver(); viewResolver.setCache(false); viewResolver.setPrefix(""); viewResolver.setSuffix(".ftl"); viewResolver.setContentType("text/html; charset=utf-8"); return viewResolver; }
Base Layout <@layout.block name="head"> @layout.block> <@layout.block name="header"> Base Layout @layout.block> <@layout.block name="contents"> Contents will be here @layout.block> <@layout.block name="footer"> Footer base @layout.block>
<@layout.block name="contents">
Footer base
<@layout.extends name="layouts/base.ftl"> <@layout.put block="head"> @layout.put> <@layout.put block="header" type="prepend"> Index Page @layout.put> <@layout.put block="contents"> blah.. blah.. @layout.put> <@layout.put block="footer" type="replace"> Footer replaced by index @layout.put> @layout.extends>
blah.. blah..
Footer replaced by index
See freemarker-template-inheritance
Gradle dependencies
Spring 配置
使用
base.ftl: layout
view.ftl : contents