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

文章: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 학습자의 빠른 성장을 도와주세요!