Java 弹簧靴&x2B;FreeMarker+;RestController加载模板

Java 弹簧靴&x2B;FreeMarker+;RestController加载模板,java,spring,spring-boot,freemarker,Java,Spring,Spring Boot,Freemarker,我使用FreeMarker作为一种方法来构造字符串,这些字符串是作为对REST请求的响应而放置在线路上的POJO的属性。我已经将Freemarker添加到项目的Maven pom中,并且我可以将配置注入到我的服务中,尽管为了让类加载器找到我的模板,我必须做一件特殊的事情 private Template getTemplate() throws Exception { configuration.setClassForTemplateLoading(this.getCl

我使用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
生成
freemarkerconfiguer
根本不会影响配置。

您可以将ftl模板放在src/main/resources/templates文件夹中,它将自动识别为免费标记版本:2.3.26-spring boot中的孵化。否则,请在application.properties文件中使用以下代码,并在使用的位置自动关联对象

spring.freemarker.template-loader-path=relativefolder/

您可以将ftl模板放在src/main/resources/templates文件夹中,它将自动识别为免费标记版本:2.3.26-spring boot中的孵化。否则,请在application.properties文件中使用以下代码,并在使用的位置自动关联对象

spring.freemarker.template-loader-path=relativefolder/

您可以将
spring.freemarker.template loader path=classpath:/template/#逗号分隔的模板路径列表。
放入应用程序属性中。(或者按照惯例,使用带有s的
模板
)您可以将
spring.freemarker.template loader path=classpath:/template/#逗号分隔的模板路径列表放入应用程序属性中。
。(或者遵循惯例,使用带有s的
模板