springboot整合freemarker(转)
- 添加依赖
<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);
}
}
- 测试
在浏览器中输入http://localhost:8080/demo
结果如下:
源代码链接: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(转)的更多相关文章
- springboot整合freemarker
前后端分离现在越来越多,如何有效的使用springboot来整合我们的页面是一个很重要的问题. springboot整合freemarker有以下几个步骤,也总结下我所犯的错误: 1.加依赖: 2.配 ...
- springboot 整合 freemarker
springboot 整合 freemarker 依赖 <parent> <groupId>org.springframework.boot</groupId> & ...
- SpringBoot整合freemarker 引用基础
原 ElasticSearch学习笔记Ⅲ - SpringBoot整合ES 新建一个SpringBoot项目.添加es的maven坐标如下: <dependency> <groupI ...
- 【SpringBoot】09.SpringBoot整合Freemarker
SpringBoot整合Freemarker 1.修改pom文件,添加坐标freemarker启动器坐标 <project xmlns="http://maven.apache.org ...
- SpringBoot学习8:springboot整合freemarker
1.创建maven项目,添加pom依赖 <!--springboot项目依赖的父项目--> <parent> <groupId>org.springframewor ...
- SpringBoot整合Freemarker+Mybatis
开发工具 , 开始 新建工程 .选择Spring Initializr 下一步 下一步,选择需要的组件 ..改一下工程名,Finish ..目录结构 首先,修改pom文件 然后,将applicatio ...
- Spring-Boot整合freemarker引入静态资源css、js等
一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...
- Spring-Boot整合freemarker引入静态资源css、js等(转)
一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...
- springboot整合freemarker模板引擎后在页面获取basePath绝对路径
在项目中引用静态资源文件或者进行ajax请求时我们有时候会使用 ${basePath} ,其实这就是一种获取绝对路径的方式: 那么在springboot项目中要怎么配置才能使用 basePaht呢? ...
随机推荐
- android 获取蓝牙已连接设备
蓝牙如果手动配对并已连接,获取连接的设备: 1.检测连接状态: int a2dp = bluetoothAdapter.getProfileConnectionState(BluetoothProfi ...
- android图像处理系列之四-- 给图片添加边框(上)
图片处理时,有时需要为图片加一些边框,下面介绍一种为图片添加简单边框的方法. 基本思路是:将边框图片裁剪成八张小图片(图片大小最好一致,不然后面处理会很麻烦),分别对应左上角,左边,左下角,下边,右下 ...
- cache -- clear( 缓存清除的方法)
一:meta方法 <META HTTP-EQUIV="pragma" CONTENT="no-cache"> <META HTTP-EQUIV ...
- Domino系统从UNIX平台到windows平台的迁移及备份
单位机房的一台服务机器到折旧期了,换成了新购IBM机器X3950,而且都预装了windows 2003 server 标准版,所以只有把以前在Unix平台下跑的OA系统迁移到新的windows 200 ...
- DG应用日志相关操作
应用archive log: recover managed standby database disconnect; 应用redo logfile: recover managed stan ...
- Java: 数据类型
核心:对事物的某种规范 前提: 1.JAVA:JAVA程序的运行是以堆栈的操作来完成的 堆栈以帧为单位保存线程的状态. JVM对堆栈只进行两种操作:以帧为单位的压栈和出栈操作. 理解 ...
- react-native React Native version mismatch
android/app/build.gradle file: dependencies { compile fileTree(dir: "libs", include: [ ...
- JNDI学习总结(1)——JNDI入门
JNDI是 Java 命名与目录接口(Java Naming and Directory Interface),在J2EE规范中是重要的规范之一,不少专家认为,没有透彻理解JNDI的意义和作用,就没有 ...
- WPF框架ZFS
前文 项目开源地址(非正式版,开发版本), 码云Gitee地址: https://gitee.com/zhgg666/publicWpf XAML XAML能帮助团队真正实现UI与逻辑的剥离.XAM ...
- linux常用命令之lsof 、netstat、ipcs、ldd
一.lsof lsof(list open files)是一个列出当前系统打开文件的工具.在linux环境下,任何事物都以文件的形式存在,通过文件不仅仅可以访问常规数据,还可以访问网络连接和硬件.每行 ...