国产成人精品亚洲777人妖,欧美日韩精品一区视频,最新亚洲国产,国产乱码精品一区二区亚洲

您的位置:首頁技術文章
文章詳情頁

spring boot加載freemarker模板路徑的方法

瀏覽:60日期:2023-07-30 18:16:10

1,之前用的eclipse開發工具來加載spring boot加載freemarker模板路徑,現在換用idea卻不能使用了,所以來記錄一下加載freemarker模板三種方式,如下

public void setClassForTemplateLoading(Class clazz, String pathPrefix);public void setDirectoryForTemplateLoading(File dir) throws IOException;public void setServletContextForTemplateLoading(Object servletContext, String path);

看名字也就知道了,分別基于類路徑、文件系統以及Servlet Context。第一種是我用idea,spring boot加載freemarker配置的①首先設置spring boot加載freemarker模板的配置(代替了xml配置),如下

spring boot加載freemarker模板路徑的方法

②通過Configuration來獲取freemarker文件路徑

spring boot加載freemarker模板路徑的方法

這個方法是根據類加載路徑來判斷的,最終會執行以下代碼

FreemarkerUtil.class.getClassLoader().getResource('/template/');

第二種基于文件系統。 比如加載/home/user/template下的模板文件。

Configuration cfg = new Configuration();cfg.setDirectoryForTemplateLoading(new File('/home/user/template'));cfg.getTemplate('Base.ftl');

這樣就獲得了/home/user/template/Base.ftl這個模板文件第三種基于web project。 第二個參數是基于WebRoot下的。使用xml配置來看看

spring boot加載freemarker模板路徑的方法spring boot加載freemarker模板路徑的方法

這里注意一下第二個參數需要以 “/” 開頭。

到此這篇關于spring boot加載freemarker模板路徑的文章就介紹到這了,更多相關spring boot freemarker模板路徑內容請搜索好吧啦網以前的文章或繼續瀏覽下面的相關文章希望大家以后多多支持好吧啦網!

標簽: Spring
相關文章:
主站蜘蛛池模板: 裕民县| 宾川县| 稻城县| 延川县| 济阳县| 临桂县| 宜川县| 康乐县| 满洲里市| 阜宁县| 麻江县| 同心县| 邮箱| 彭阳县| 鲜城| 根河市| 宜兰县| 都兰县| 淅川县| 滁州市| 汪清县| 洪湖市| 耿马| 开阳县| 拉萨市| 长乐市| 高密市| 水城县| 铜鼓县| 临漳县| 射阳县| 扎囊县| 双城市| 新泰市| 泉州市| 镇赉县| 全州县| 宿松县| 镶黄旗| 许昌县| 龙海市|