spring - java freemarker没有@extends,@block这些指令?
大家讲道理
大家讲道理 2017-04-18 10:50:40
0
1
979

文章:http://csjava.blog.163.com/bl...

那我用maven怎么下载这个依赖

大家讲道理
大家讲道理

光阴似箭催人老,日月如移越少年。

全部回复 (1)
巴扎黑

See freemarker-template-inheritance

Gradle dependencies

dependencies { compile 'kr.pe.kwonnam.freemarker:freemarker-template-inheritance:0.4.RELEASE' }

Spring 配置

@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.ftl: layout

   Base Layout <@layout.block name="head">   
<@layout.block name="header">

Base Layout

<@layout.block name="contents">

Contents will be here

<@layout.block name="footer">

Footer base

view.ftl : contents

<@layout.extends name="layouts/base.ftl"> <@layout.put block="head">   <@layout.put block="header" type="prepend"> 

Index Page

<@layout.put block="contents">

blah.. blah..

<@layout.put block="footer" type="replace">
    最新下载
    更多>
    网站特效
    网站源码
    网站素材
    前端模板
    关于我们 免责声明 Sitemap
    PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!