• 添加依赖
<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. Windows7下修改pip源

    以下列举三种方式的pip源配置: 1. 设置环境变量PIP_CONFIG_FILE指向pip.ini源配置文件,pip.ini文件内容如下: [global] index-url = http://m ...

  2. xadmin列表页添加自定义工具栏toolbar

    通过xadmin的Plugin实现,adminx.py中 class Link2AdminPlugin(BaseAdminPlugin): link_2_admin = False def init_ ...

  3. PS实现分幅扫描图片的批量自己主动拼接

    非常easy,仅仅需两步搞定: 一.打开工具.如图所看到的:   二.选择图片,进行拼接:   静待结果!

  4. Oracle HR 例子用户的建立 10g,11g均可

    Oracle HR 例子用户的建立 10g,11g均可 先将附件(见文章尾部)上的 10 个 .sql 文件放入这个路径中 : $ORACLE_HOME/demo/schema/human_resou ...

  5. virtual与override

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  6. vue 点击事件阻止冒泡 用stop

    1.使用vue阻止子级元素的click事件冒泡,很简单,用stop.eg: @click.stop='xxx'

  7. background 背景认知

    background 背景 背景颜色 /*背景颜色为红色*/ p { background-color:ren; } 网页背景不仅可以设置颜色还可以插入图片 /*为背景插入图片*/ body { ba ...

  8. 今日题解------codeforces 895C

    题意:给你一个数列,然后找任意数量的数字(除了空集),使得他们的乘机为一个数的平方 我们发现元素最大70,所以我们可以从这里入手,平方数有个性质就是它的所有质因子的指数为偶数 比如:36 = 2*2* ...

  9. HDU——T 1711 Number Sequence

    http://acm.hdu.edu.cn/showproblem.php?pid=1711 Time Limit: 10000/5000 MS (Java/Others)    Memory Lim ...

  10. 怎样利用ash监控会话

    ash是很有效的监控工具之中的一个.1秒抓一次 select max(sample_time)over(),min(sample_time)over() from dba_hist_active_se ...