zoukankan      html  css  js  c++  java
  • Freemarker提供了3种加载模板目录的方法

    Freemarker提供了3种加载模板目录的方法

    原创 2016年08月24日 14:50:13

    Freemarker提供了3种加载模板目录的方法。 它使用Configuration类加载模板。

    三种方法分别是:

    public void setClassForTemplateLoading(Class clazz, String pathPrefix);

    public void setDirectoryForTemplateLoading(File dir) throws IOException;

    public void setServletContextForTemplateLoading(Object servletContext, String path);


    第一种:基于类路径,HttpWeb包下的framemaker.ftl文件
      configuration.setClassForTemplateLoading(this.getClass(), "/HttpWeb");

    configuration.getTemplate("framemaker.ftl"); //framemaker.ftl为要装载的模板 
    第二种:基于文件系统

    configuration.setDirectoryForTemplateLoading(new File("/template"))

    configuration.getTemplate("framemaker.ftl"); //framemaker.ftl为要装载的模板

    第三种:基于Servlet Context,指的是基于WebRoot下的template下的framemaker.ftl文件

    HttpServletRequest request = ServletActionContext.getRequest();

    configuration.setServletContextForTemplateLoading(request.getSession().getServletContext(), "/template");

    configuration.getTemplate("framemaker.ftl"); //framemaker.ftl为要装载的模板

  • 相关阅读:
    我的python菜鸟之路11
    我的SAS菜鸟之路9
    我的python菜鸟之路10
    idea中tomcat9打印日志乱码
    2、dockerfile命令
    1、Docker 打包本地镜像
    1、Centos7下MongoDB下载安装详细步骤
    4、自定义service 服务
    3、杀死某个服务下的多个进程
    3、python导出依赖环境时报错
  • 原文地址:https://www.cnblogs.com/taiyanhong/p/8479247.html
Copyright © 2011-2022 走看看