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