使用步骤:

1、在pom.xml中添加相关依赖

  <!-- 添加freemarker依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>

2、关闭freemarker缓存

spring.freemarker.cache=false
spring.freemarker.allow-request-override=false # Set whether HttpServletRequest attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.allow-session-override=false # Set whether HttpSession attributes are allowed to override (hide) controller generated model attributes of the same name.
spring.freemarker.cache=false # Enable template caching.
spring.freemarker.charset=UTF-8 # Template encoding.
spring.freemarker.check-template-location=true # Check that the templates location exists.
spring.freemarker.content-type=text/html # Content-Type value.
spring.freemarker.enabled=true # Enable MVC view resolution for this technology.
spring.freemarker.expose-request-attributes=false # Set whether all request attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-session-attributes=false # Set whether all HttpSession attributes should be added to the model prior to merging with the template.
spring.freemarker.expose-spring-macro-helpers=true # Set whether to expose a RequestContext for use by Spring's macro library, under the name "springMacroRequestContext".
spring.freemarker.prefer-file-system-access=true # Prefer file system access for template loading. File system access enables hot detection of template changes.
spring.freemarker.prefix= # Prefix that gets prepended to view names when building a URL.
spring.freemarker.request-context-attribute= # Name of the RequestContext attribute for all views.
spring.freemarker.settings.*= # Well-known FreeMarker keys which will be passed to FreeMarker's Configuration.
spring.freemarker.suffix= # Suffix that gets appended to view names when building a URL.
spring.freemarker.template-loader-path=classpath:/templates/ # Comma-separated list of template paths.
spring.freemarker.view-names= # White list of view names that can be resolved.

3、编写模板文件.ftl

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org"
xmlns:sec="http://www.thymeleaf.org/thymeleaf-extras-springsecurity3">
<head>
<meta charset="UTF-8" />
<title>Insert title here</title>
</head>
<body>
<h1 th:inlines="text">Hello</h1>
<p th:text="${hello}"></p>
</body>
</html>

4、编写访问文件的controller

@Controller
public class FreemarkerController { @RequestMapping("index")
public String indexHtml(Map<String, Object> map){
map.put("hello", "this is a freemarker test");
return "/index";
}
}

最新文章

  1. 卷积神经网络_(4)_caffe简介
  2. Oracle存储过程中异常Exception的捕捉和处理
  3. vim编辑下Python2.0自动补全
  4. 软件测试作业3--Junit、hamcrest、eclemmat的安装和使用
  5. mssql 下删除 default 值的Sql写法
  6. 深入.Net字符串类型
  7. 解析XML文档之二:使用PULL解析
  8. Android CoordinatorLayout + AppBarLayout(向上滚动隐藏指定的View)
  9. hdu1848 Fibonacci again and again(SG游戏功能)
  10. JavaScript设计模式_02_策略模式
  11. Web API 路由 [一] Convention-Based Routing
  12. java 使用for循环打印杨辉三角形
  13. 第五讲 DOM基础
  14. java接口中的继承
  15. Hbase学习笔记——基本CRUD操作
  16. sparse.coo_matrix()
  17. 第五周可执行代码 以及 Canvas 制作个人PSP分类饼图
  18. Android -- isInEditMode
  19. hdu 5086 Revenge of Segment Tree(BestCoder Round #16)
  20. 【WP8】扩展CM的INavigationService方法

热门文章

  1. linux 终端操作快捷键
  2. 相似度模型 similarity model
  3. iOS 多线程之 GCD 的基本使用
  4. Vue.js之组件嵌套
  5. PHP的文件下载
  6. Android系统移植与调试之------->增加一个双击物理按键打开和关闭闪光灯并将闪光灯状态同步到下拉菜单中
  7. Eclipse中svn操作
  8. vue-cli 搭建项目
  9. Python学习笔记2_Python基础
  10. rar 7z文件打包