Spring Boot入门教程-FreeMarker模板
来源:互联网 发布:微传单软件 编辑:程序博客网 时间:2024/05/18 03:45
这篇博客写一下Spring Boot 如何使用FreeMarker 。与Spring 繁琐的xml配置相别,SpringBoot 集成FreeMarler简直太省心。
注意:这篇文章所用的项目是在前边几篇博客所介绍的项目基础上进行的,如果感到不知所云的话,请参考之前的博客。
闲话不多说,正式开始。
1.首先在pom.xml中加入依赖
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-freemarker</artifactId></dependency>2.在application.properties中对FreeMarker进行配置
###########################################################FREEMARKER########################################################spring.freemarker.allow-request-override=falsespring.freemarker.cache=truespring.freemarker.check-template-location=truespring.freemarker.charset=UTF-8spring.freemarker.content-type=text/htmlspring.freemarker.expose-request-attributes=falsespring.freemarker.expose-session-attributes=falsespring.freemarker.expose-spring-macro-helpers=falsespring.freemarker.prefix=#spring.freemarker.request-context-attribute=#spring.freemarker.settings.spring.freemarker.suffix=.ftlspring.freemarker.template-loader-path=classpath:/templates/#spring.freemarker.view-names= # whitelist of view names that can be resolved
3.在/resources/templates创建一个模板文件index.ftl
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8"> <title>Title</title></head><body>${hello}</body></html>4.在DemoController中添加以下代码
@RequestMapping("indexPage") public String helloFtl(Map<String,Object> map) { map.put("hello","Hello FreeMarker"); return "index"; }5,启动项目在浏览器中输入http://localhost:8080/indexPage
这就是我们想要的结果,非常的简单。
阅读全文
0 0
- Spring Boot入门教程-FreeMarker模板
- spring boot 使用FreeMarker模板
- spring boot 使用FreeMarker模板
- Spring boot 使用freemarker模板
- (9) spring boot使用freemarker模板引擎
- Spring boot配置freemarker,jsp,velocity模板
- 93.Spring Boot使用模板freemarker【从零开始学Spring Boot】
- 《spring-boot学习》-14-spring boot整合freeMarker模板
- Spring Boot基础6-web应用开发-模板引擎FreeMarker
- spring-boot配置html模板引擎freemarker、thymeleaf
- Spring boot freemarker模板路径的几种设置方式
- Spring Boot整合模板引擎freemarker以及servlet
- spring- boot 发送邮件接口+freemarker视图模板引擎
- spring boot 整合Freemarker
- Spring Boot 集成 FreeMarker
- spring boot+mybatis+freemarker
- spring boot之FreeMarker
- Spring Boot入门教程
- 自定义input默认placeholder样式
- 怎样理解阻塞非阻塞与同步异步的区别?
- Stack介绍以及设计一个有getMin 功能的栈
- CAS实现单点登录SSO执行原理探究(终于明白了)
- 栈,队列和双端队列的操作
- Spring Boot入门教程-FreeMarker模板
- Android Studio教程:启动时不自动打开项目
- 我如何从一个异步调用返回响应?
- Linux shell script 1 basic scripts
- Oracle之快速复制表-yellowcong
- 修改kafka_run_class.bat并增加JRE_HOME判断
- HTML5客户端数据存储Web Storage——localStorage与sessionStorage
- Hibernate与 MyBatis的比较
- MySQL性能利器:innotop工具