SpringBoot与Freemarker整合

发布时间 2023-07-12 13:39:57作者: ing88

1.需要导入freemarker的pom文件;

<dependency>
  <groupId>org.springframework.boot</groupId>
  <artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>



2.需要在application.properties配置文件中配置一些freemarker的参数;
serve.port=8082
#freemarker模板配置
spring.freemarker.suffix=.ftl
spring.freemarker.content-type=text/html
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
#freemarker\u7684\u6A21\u7248\u4FDD\u5B58\u8DEF\u5F84\uFF08\u6B63\u5E38\u60C5\u51B5\u4E0B\uFF0C\u6B64\u9879\u4E0D\u9700\u8981\u653E\u5F00,springboot\u9ED8\u8BA4\u5C31\u662Ftemplates\u8DEF\u5F84\uFF0C\u6253\u5F00\u4EE5\u540E\u53CD\u800C\u9700\u8981\u5728\u6A21\u7248\u91CC\u9762\u6DFB\u52A0templates\u76EE\u5F55\uFF09
#spring.freemarker.templates-loader-path=classpath:/templates
spring.freemarker.request-context-attribute=ctx
spring.devtools.restart.additional-paths: src/main/java

3.在controller中需要写一个跳转路径;测试一下即可;
@RequestMapping("/index")
public String index(){
    return "index";
}