简体   繁体   English

FreeMarker Spring MVC导入问题

[英]FreeMarker Spring MVC issue with import

I have issue when importing files in freemarker. 在freemarker中导入文件时出现问题。 My folder structure looks like this: 我的文件夹结构如下所示: 档案结构

And in my index I have code like this: 在我的索引中,我有这样的代码:

<#import "../layouts/standart.ftl" as layout>
<@layout.test>
<div><h1>Hello Dude</h1></div>
</@layout.test>

My template looks like this: 我的模板如下所示:

<#macro test>
<html>
...
</html>
</#macro>

Here is part of the exception that I get when I try to access page. 这是我尝试访问页面时遇到的异常的一部分。

FreeMarker template error: Error reading imported template ../layouts/standart.ftl The failing instruction (FTL stack trace): ---------- ==> #import "../layouts/standart.ftl" as ... [in template "index.ftl" at line 1, column 1] ---------- Java stack trace (for programmers): ---------- freemarker.core._MiscTemplateException: [... Exception message was already printed; FreeMarker模板错误:读取导入的模板../layouts/standart.ftl时出错。失败的指令(FTL堆栈跟踪):---------- ==> #import“ ../layouts/standart.ftl” as ... [在第1行第1列的模板“ index.ftl”中] ---------- Java堆栈跟踪(对于程序员):---------- freemarker.core ._MiscTemplateException:[...异常消息已经被打印; see it above ...] at freemarker.core.LibraryLoad.accept(LibraryLoad.java:118) at What am I doing wrong? 请参阅以上内容...]在freemarker.core.LibraryLoad.accept(LibraryLoad.java:118)处,我做错了什么? Thanks for any advice. 感谢您的任何建议。

You can configure where Freemarker will look for templates in your application context xml file. 您可以配置Freemarker在应用程序上下文xml文件中查找模板的位置。 These paths are relative to your application context path. 这些路径是相对于您的应用程序上下文路径的。 For example 例如

<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
    <property name="templateLoaderPaths">
        <list>
            <value>/views/</value>
            <value>/templates/</value>
        </list>
    </property> 
</bean>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM