前面咱们已经实现了thymeleaf模板,其实Freemarker和thymeleaf差很少,均可以取代JSP页面,实现步骤也差很少,咱们来简单实现一下css
引入pom.xml依赖以下html
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
复制代码
建立Controller测试类spring
/**
* @author pillarzhang
* @date 2019-06-03
*/
@Controller
class FreemarkerController {
@RequestMapping("/index")
public String index(Model model){
model.addAttribute("name","hello pillar");
return "index";
}
}
复制代码
application.properties配置文件你能够选择不配置默认,也能够进行手动配置bash
选择默认时配置路径必定要写对,src/main/resources static(js,css等静态文件),templates(页面路径)注意是ftl后缀mvc
若是要自定义的话,能够在application.properties中设置以下等配置信息app
spring.freemarker.charset=UTF-8
spring.freemarker.suffix=.ftl
spring.freemarker.content-type=text/html; charset=utf-8
spring.freemarker.template-loader-path=classpath:/templates
spring.mvc.static-path-pattern=/static/**
复制代码
Index.ftl文件以下spring-boot
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>FreeMarker</title>
</head>
<body>
<h1>hello world</h1>
<h1 style="color: red">${name}</h1>
</body>
</html>
复制代码
启动项目,输入地址http://localhost:8080/index显示以下则成功post
若是遇到问题,能够结合集成thymeleaf出现的错误进行排查测试