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