1. freemarker 配置 模板加載路徑
application.yml
# freemarker
freemarker:
suffix: .ftl
content-type: text/html
charset: UTF-8
template-loader-path: classpath:/views/
settings:
classic_compatible: true
文件目錄如下
要求 :子目錄(/views/user)中的password.ftl加載父目錄的common.ftl
報錯 :Template not found for name "../common.ftl"
解決:用絕對路徑。
<#include "*/common.ftl">
*/common.ftl 會從當前文件的父目錄開始遍歷直到找到common.ftl
參考:模板加載 - FreeMarker 中文官方參考手冊 (foofun.cn)