• 添加依赖
<dependency>

<groupId>org.springframework.boot</groupId>

<artifactId>spring-boot-devtools</artifactId>

<optional>true</optional>

</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>
  • 编写配置文件(application.yml)
spring:

freemarker:

cache: false

为了实现热部署,这里仅配置一下freemarker的缓存,关于freemarker的其它配置使用默认即可。

  • 创建freemarker模板

    在src/java/resources目录下创建templates文件夹并创建demo.ftl。

    模板默认是从【classpath:/templates/】这个位置查找的。

    demo.ftl文件内容如下:
<!DOCTYPE html>

<html>

<head>

<meta charset="UTF-8">

<title>Insert title here</title>

</head>

<body>

请看说明:${descrip} <br />
haahaaaa
</body>

</html>
  • 创建web层辅助类
@Controller

public class FreemarkerController {

@RequestMapping("/demo")

public String demo(Map<String, Object> map) {

map.put("descrip", "It's a springboot integrate freemarker's demo!!!!");

return "demo";

}
}
  • 创建测试启动类
@SpringBootApplication

public class Application {

public static void main(String[] args) throws Exception {

SpringApplication.run(Application.class, args);

}
}

源代码链接:https://github.com/myNameIssls/springboot-study

参考链接:https://github.com/spring-projects/spring-boot/tree/master/spring-boot-samples

关于springboot配置文件中的属性及freemarker的配置可参考链接:

http://docs.spring.io/spring-boot/docs/1.5.3.RELEASE/reference/htmlsingle/#appendix

springboot整合freemarker(转)的更多相关文章

  1. springboot整合freemarker

    前后端分离现在越来越多,如何有效的使用springboot来整合我们的页面是一个很重要的问题. springboot整合freemarker有以下几个步骤,也总结下我所犯的错误: 1.加依赖: 2.配 ...

  2. springboot 整合 freemarker

    springboot 整合 freemarker 依赖 <parent> <groupId>org.springframework.boot</groupId> & ...

  3. SpringBoot整合freemarker 引用基础

    原 ElasticSearch学习笔记Ⅲ - SpringBoot整合ES 新建一个SpringBoot项目.添加es的maven坐标如下: <dependency> <groupI ...

  4. 【SpringBoot】09.SpringBoot整合Freemarker

    SpringBoot整合Freemarker 1.修改pom文件,添加坐标freemarker启动器坐标 <project xmlns="http://maven.apache.org ...

  5. SpringBoot学习8:springboot整合freemarker

    1.创建maven项目,添加pom依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewor ...

  6. SpringBoot整合Freemarker+Mybatis

    开发工具 , 开始 新建工程 .选择Spring Initializr 下一步 下一步,选择需要的组件 ..改一下工程名,Finish ..目录结构 首先,修改pom文件 然后,将applicatio ...

  7. Spring-Boot整合freemarker引入静态资源css、js等

    一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...

  8. Spring-Boot整合freemarker引入静态资源css、js等(转)

    一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...

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

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

随机推荐

  1. android开发使用SQLite之写日记

    使用数据库实现对数据的存储. 以下上一个小样例,写日记. 效果例如以下:           当LIstView中没有数据显示时,我们须要告诉用户没有数据. 方法有二: 1. activity继承Li ...

  2. CSS Text

    http://www.runoob.com/css/css-text.html 文本颜色 颜色属性被用来设置文字的颜色. 颜色是通过CSS最经常的指定: 十六进制值 - 如: #FF0000 一个RG ...

  3. 修改url中某个参数

    function changeURLArg(url,arg,arg_val){ var pattern=arg+'=([^&]*)'; var replaceText=arg+'='+arg_ ...

  4. JOISC 2018 Day 2 最差记者3

    JOISC 2018 Day 2 最差记者3 题意: ​ 数轴上有\(N\)个选手和一个旗手,旗手在位置\(0\)<第\(i\)人的位置为\(-i\),每个选手有一个参数\(D_i\).旗手每单 ...

  5. arp---操作主机的arp缓冲区

    简介 arp命令用于操作主机的arp缓冲区,可以用来显示arp缓冲区中的所有条目.删除指定的条目或者添加静态的ip地址与MAC地址对应关系. 选项 -a<主机>:显示arp缓冲区的所有条目 ...

  6. dp之完全背包 hdu--2159一维数组做法

    #include <iostream>#include <stdio.h>#include <string.h>using namespace std;int ma ...

  7. 窗体是不出现在Alt+Tab中(窗体不出现在任务管理器中的应用程序列中)

    窗体是不出现在Alt+Tab中和不出现在任务管理器中的应用程序中 重写 CreateParams即可: public class MyForm : Form{ protected override C ...

  8. MyBatis学习总结(11)——MyBatis动态Sql语句

    MyBatis中对数据库的操作,有时要带一些条件,因此动态SQL语句非常有必要,下面就主要来讲讲几个常用的动态SQL语句的语法 MyBatis中用于实现动态SQL的元素主要有: if choose(w ...

  9. 经验之谈—让你看明确block

    事实上我感觉不常常使用block的朋友.对block应该是比較陌生的,那么如今我们来扒开block的真面目,看看block的本质 普通的局部变量.block内部仅仅会引用它初始的值(block定义那一 ...

  10. LINUX下为apache 和 PHP 添加模块

    LINUX下为apache 和 PHP 添加模块https://www.path8.net/tn/archives/4717/opt/lampp/bin/httpd -V/opt/lampp/bin/ ...