前面咱们已经实现了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配置文件你能够选择不配置默认,也能够进行手动配置mvc
选择默认时配置路径必定要写对,src/main/resources static(js,css等静态文件),templates(页面路径)注意是ftl后缀 app
若是要自定义的话,能够在application.properties中设置以下等配置信息spring-boot
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文件以下测试
<!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显示以下则成功spa
若是遇到问题,能够结合集成thymeleaf出现的错误进行排查.net