[英]Spring Boot + FreeMarker + RestController loading templates
我正在使用FreeMarker作為一種構造字符串的方法,這些字符串是作為對REST請求的響應而放在線上的POJO的屬性。 我已經將Freemarker添加到項目的Maven pom中,我可以將配置注入到我的服務中,盡管我必須做一個特殊的事情才能讓類加載器找到我的模板。
private Template getTemplate() throws Exception {
configuration.setClassForTemplateLoading(this.getClass(), "/template/");
Template temp = configuration.getTemplate("test.ftl");
return temp;
}
有沒有更簡潔的方法來配置FreeMarker尋找模板的位置? 使用@Bean
生成FreeMarkerConfigurer
根本不會影響配置。
http://freemarker.org/docs/pgui_config_templateloading.html
您可以將ftl模板放在src / main / resources / templates文件夾中,它將自動識別為免費標記版本:2.3.26-在spring boot中孵化。 否則,請在application.properties文件中使用以下代碼,並自動裝配使用的對象。
spring.freemarker.template-loader-path=relativefolder/
https://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.