SpringBoot实战之9 整合freemarker模版引擎
2017-12-04 09:20
465 查看
一、简介
springboot支持多种模版引擎包括:1. FreeMarker
2. Groovy
3. Thymeleaf (Spring 官网使用这个)
4. Velocity
5. JSP (SpringBoot官方不推荐使用)
下面练习freemarker的使用。
二、导包
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-freemarker</artifactId> </dependency>
三、controller层
@Controller public class ViewController { /** * @description <p></p> * @return * @author heshiyuan * @date 2017/12/2 20:56 */ @RequestMapping(value = {"/","/index"}) public String index(HttpServletRequest request){ request.setAttribute("content","this is index"); return "index" ; } }
四、配置页面
index.ftl<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>this is index</title> </head> <body> <h1>${content}</h1> </body> </html>
五、启动
@SpringBootApplication public class SpringBootFreemarkerApplication { public static void main(String[] args) { SpringApplication.run(SpringBootFreemarkerApplication.class,args); } }
六、项目结构图
历史文章
SpringBoot实战之入门springboot实战之文章汇总
springboot实战之读取配置文件
springboot实战之整合jsp模版引擎
相关文章推荐
- Spring Boot 构建应用——整合 Freemarker 模版引擎
- springboot如何使用Freemarker模版引擎
- Spring Boot 构建应用——整合 Thymeleaf 模版引擎
- Spring Boot整合模板引擎freemarker以及servlet
- Spring Boot学习之旅:(十三)模版引擎-FreeMarker
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- spring boot整合freemarker出现Whitelabel Error Page问题
- 实战Java模版引擎Freemarker
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- SpringBoot学习-(二十)SpringBoot整合Freemarker
- spring boot实战(第十四篇)整合RabbitMQ源码分析前言
- JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎
- Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)
- SpringBoot实战之10 整合jdbc进行crud操作
- spring boot实战(第十二篇)整合RabbitMQ
- SpringBoot系列三之 MVC 模版引擎
- Spring Boot整合Freemarker
- RabbitMQ 实战(二)Spring Boot 整合 RabbitMQ
- springboot整合freemarker生成静态HTML页面