导入依赖

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

application.properties文件中新增freemarker配置

## Freemarker 配置
spring.freemarker.template-loader-path=classpath:/templates/
spring.freemarker.cache=false
spring.freemarker.charset=UTF-
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=false
spring.freemarker.expose-session-attributes=false
spring.freemarker.request-context-attribute=request
spring.freemarker.prefix=/
spring.freemarker.suffix=.ftl

在src/main/resource/templates文件夹中创建helloFtl.ftl文件

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>index01</title>
</head>
<body>
欢迎:
<#list listThree as three >
${three}
</#list>
</body>
</html>

创建controller层

@Controller
@RequestMapping("/free")
public class FreeMarkerController {
@RequestMapping("/getThree")
public String getThree(ModelMap map){
List<String> list=new ArrayList<>();
list.add("aa");
list.add("bb");
map.put("listThree",list);
return "index";
}
}

浏览器测试

    

SpringBoot使用freemarker模板的更多相关文章

  1. springboot 使用FreeMarker模板(转)

    在spring boot中使用FreeMarker模板非常简单方便,只需要简单几步就行: 1.引入依赖: <dependency> <groupId>org.springfra ...

  2. SpringBoot获取Freemarker模板引擎,生成HTML代码

    今天用Ajax异步添加评论,加载Freemarker模板引擎,生成模板模块 1.新建Freemarker模板 <li id="${comment.oId}"> < ...

  3. springboot整合freemarker模板引擎后在页面获取basePath绝对路径

    在项目中引用静态资源文件或者进行ajax请求时我们有时候会使用 ${basePath} ,其实这就是一种获取绝对路径的方式: 那么在springboot项目中要怎么配置才能使用 basePaht呢? ...

  4. SpringBoot整合freemarker模板

    一.目录展示 二.导入依赖 三.application.properties配置文件 四.在src/main/resource/templates文件夹中创建HelloFreeMarker.ftl文件 ...

  5. springboot之freemarker 和thymeleaf模板web开发

    Spring Boot 推荐使用Thymeleaf.FreeMarker.Velocity.Groovy.Mustache等模板引擎.不建议使用JSP. 一.Spring Boot 中使用Thymel ...

  6. 使用 FreeMarker模板 Springboot 发送邮件

    四.使用 FreeMarker模板 HTML 标签的字符串拼接是一件很棘手的事.因为在你的大脑中解析HTML标签并想象它在渲染时会是什么样子是挺困难的.而将HTML混合在Java代码中又会使得这个问题 ...

  7. SpringBoot集成freemarker和thymeleaf模板

    1.在MAVEN工程POM.XML中引入依赖架包 <!-- 引入 freemarker 模板依赖 --> <dependency> <groupId>org.spr ...

  8. SpringBoot基础及FreeMarker模板

    案例springboot_freemarker application.properties配置文件 ###FreeMarker配置 spring.freemarker.template-loader ...

  9. Springboot模板(thymeleaf、freemarker模板)

    目的: 1.thymeleaf模板 2.Freemarker模板 thymeleaf模板 thymeleaf 的优点: 支持html5标准,页面无须部署到servlet开发到服务器上,直接通过浏览器就 ...

随机推荐

  1. maven安装与在eclipse中配置

    需要准备 eclipse maven压缩包 : http://maven.apache.org/download.cgi 1 解压maven压缩包 2 在系统变量中新建变量MAVEN_HOME,值为 ...

  2. jsp页面不乱码,外部引用的js弹出对话框乱码

    今天在做一个课程设计的时候,写到一个界面注册,在用js判断数据的正确性时,碰到了一个js弹出框的乱码问题.在网上找寻了很久,也找了很多博客看,但是发现怎么样都不能解决我的问题,下面给出几个比较经典的解 ...

  3. EXISTS的用法介绍

    比如在Northwind数据库中有一个查询为 SELECT c.CustomerId,CompanyName FROM Customers c WHERE EXISTS( SELECT OrderID ...

  4. Docker学习-Spring Boot on Docker

    1.创建spring boot项目 https://start.spring.io/ pom.xml文件新增docker支持 <build> <plugins> <plu ...

  5. [LC]141题 Intersection of Two Linked Lists (相交链表)(链表)

    ①中文题目 编写一个程序,找到两个单链表相交的起始节点. 如下面的两个链表: 在节点 c1 开始相交. 注意: 如果两个链表没有交点,返回 null.在返回结果后,两个链表仍须保持原有的结构.可假定整 ...

  6. 并发编程-深入浅出AQS

    AQS是并发编程中非常重要的概念,它是juc包下的许多并发工具类,如CountdownLatch,CyclicBarrier,Semaphore 和锁, 如ReentrantLock, ReaderW ...

  7. 一分钟带你了解下Spring Security!

    一.什么是Spring Security? Spring Security是一个功能强大且高度可定制的身份验证和访问控制框架,它是用于保护基于Spring的应用程序的实际标准. Spring Secu ...

  8. pat 1058 A+B in Hogwarts(20 分)

    1058 A+B in Hogwarts(20 分) If you are a fan of Harry Potter, you would know the world of magic has i ...

  9. 【dp】you are the one

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4283 题解: 当最优解下, a1在j的位置排出, 则a2 ——aj-1 和 aj——an为两个独立事件 ...

  10. vim用户手册笔记常用操作整理

    "x"命令可以删除一个字符 "d"命令可以后跟任何一个位移命令,它将删除从当前光标起到位移的终点处的文本内容dw "c",改变命令例如cw ...