版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/ljk126wy/article/details/82729626
SpringBoot 官方比较推荐使用thymeleaf,由于自己对freemarker相对比较熟悉,所以这里我们介绍一下如何使用ftl当前前端页面使用。
1 在pom 中引入 spring-boot-starter-freemarker
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2 在resources 下 templates 创建test目录新建 freemarkDemo.ftl 内容如下
<h1>springBoot freemark hello world!</h1>
3 创建Controller 跳转ftl 页面
package cn.lijunkui.springbootlearn.freemark;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
@Controller
@RequestMapping("/ftlDemo")
public class FtlController {
@RequestMapping("/test")
public String test(){
return "test/freemarkerDemo";
}
}
4 游览器访问Controller 进行测试