freemarker加载模板文件的三种方法

xiaoxiao2021-02-28  121

freemarker加载模板文件的三种方法

加载类路径

Configuration cfg= new Configuration();          freemarkerCfg.setClassForTemplateLoading(this.getClass(), "/");//类路径Template template = cfg.getTemplate(x.ftl);        

加载绝对路径

cfg.setDirectoryForTemplateLoading(new File(System .getProperty("user.dir") + "\\template"));//绝对路径  Template template = cfg.getTemplate(x.ftl);  加载WEB路径 cfg.setServletContextForTemplateLoading(getServletContext(),"/templates");//webroot路径Template template = cfg.getTemplate(x.ftl);         
转载请注明原文地址: https://www.6miu.com/read-20156.html

最新回复(0)