2016-04-30 57 views
0

我使用Spring框架为我的web应用和 我在目录网页/ WEB-INF /视图/布局主要布局application.ftlSpring框架Freemarker的宏观布局,嵌套不起作用

<#macro layout> 
    <!doctype html> 
    <html lang="en"> 
    <head> 
     <meta charset="UTF-8"> 
     <title>Document</title> 
    </head> 
    <body> 
     Some content here 
    <#nested> 
     Some content here 
    </body> 
    </html></#macro> 

而且在目录中的Web/WEB-INF /人次另一页, 例如page1.ftl

<@layout>This is the page one</@layout> 

和第2页FTL。

<@layout>This is the page two</@layout> 

但它不起作用。我的调度程序-servlet.xml

<?xml version="1.0" encoding="UTF-8"?> 
<beans xmlns="http://www.springframework.org/schema/beans" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xmlns:context="http://www.springframework.org/schema/context" 
     xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:p="http://www.springframework.org/schema/p" 
     xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc.xsd"> 
    <import resource="spring/spring-aop.xml" /> 
    <context:component-scan base-package="com.birthright.controllers"/> 
    <context:annotation-config/> 
    <mvc:annotation-driven/> 
    <mvc:resources mapping="/resources/**" location="WEB-INF/resources/"/> 

    <bean id="viewResolver" 
      class="org.springframework.web.servlet.view.freemarker.FreeMarkerViewResolver" 
      p:cache="true" 
      p:prefix="" 
      p:suffix=".ftl" 
      p:contentType="text/html; charset=UTF-8"/> 

    <bean id="freemarkerConfig" 
      class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer" 
      p:templateLoaderPath="/WEB-INF/views/" 
      p:defaultEncoding="UTF-8"> 
     <property name="templateLoaderPaths"> 
      <list> 
       <value>/WEB-INF/views/layout</value> 
      </list> 
     </property> 
     <property name="freemarkerSettings"> 
      <props> 
       <prop key="datetime_format">dd-MM-yyyy HH:mm:ss</prop> 
       <prop key="number_format">0.######</prop> 
       <prop key="url_escaping_charset">UTF-8</prop> 
      </props> 
     </property> 
    </bean> 
</beans> 

回答

0

您是否试过将宏文件导入您的视图? <#import "./layout/application.ftl">

此外,如果您在WEB-INF/views /目录中有视图,则您的templateLoaderPath应该指向该目录,而不是WEB-INF/views/layout。你的配置没有指向正确的目录,所以你的视图没有找到。 <value>/WEB-INF/views</value>