springboot: 集成freemark模板引擎
1.freemark简介(摘自:http://blog.csdn.net/liaomin416100569/article/details/78349072)
在互联网软件内容网站中 一般首页的访问量大,为了提供首页的访问效率,一般 首页的内容以及其中的新闻等信息都可以实现html静态化 浏览器访问时
设置浏览器的缓存策略和生成静态页面的周期一致 可以使访问效率大大提升 同时配合cdn处理图片 js css等资源 可以在首页访问时 理论完全脱离数据库
降低应用压力
原理图:
2.代码
1).pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lf</groupId>
<artifactId>Springboot</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 继承 spring-boot-starter-paren -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.3.RELEASE</version>
</parent>
<dependencies>
<!-- SpringBoot 核心组件 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!-- 引入freeMarker的依赖包. -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
</dependencies>
</project>
2).测试类:IndexController.java
package com.lf.controller; import java.util.ArrayList;
import java.util.List; import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
public class IndexController { @RequestMapping("index")
public String index(ModelMap map){
map.put("user", "大飞");
map.put("sex", 1);
List<Object> userList = new ArrayList<Object>();
userList.add("小菜");
userList.add("老秃子");
userList.add("王麻子");
map.put("userList", userList);
return "index";
} }
3).FTL模板:index.ftl (springboot默认加载模板文件地址:/src/main/resources/templates)
<!DOCTYPE html >
<html>
<head lang="en">
<meta charset=UTF-8">
<title>Insert title here</title>
</head>
<body>
用户:${user}
性别:
<#if sex==1>
男
<#elseif sex==2>
女
<#else>
其他
</#if>
<br/><hr/>
遍历集合:
<#list userList as user>
${user}
</#list>
</body>
</html>
4).springboot启动类: ApplicationMain.java
package com.lf.application; import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.annotation.ComponentScan; @ComponentScan(basePackages="com.lf")
@EnableAutoConfiguration//此注释自动载入应用程序所需的所有Bean
public class ApplicationMain { public static void main(String[] args) {
SpringApplication.run(ApplicationMain.class, args);
} }
5).测试结果

springboot: 集成freemark模板引擎的更多相关文章
- SpringBoot集成Thymeleaf模板引擎
简单介绍 目前在JavaEE领域有几中比较常用的模板引擎,分别是Jsp.Velocity.Freemarker.Thymeleaf,对Freemark语法不是特别熟悉,不过对于前端页面渲染效率来说,j ...
- 九、SpringBoot集成Thymeleaf模板引擎
Thymeleaf咋读!??? 呵呵,是不是一脸懵逼...哥用我的大学四级英文知识告诉你吧:[θaimlif]. 啥玩意?不会音标?...那你就这样叫它吧:“赛母李府”,大部分中国人是听不出破绽的.. ...
- 「快学springboot」SpringBoot整合freeMark模板引擎
前言 虽然现在流行前后端分离开发和部署,但是有时候还是需要用到服务端渲染页面的.比如:需要考虑到SEO优化等问题的时候,FreeMark其实还是很有作用的.本人的博客本来是用React开发的,但是后来 ...
- SpringBoot系列之集成jsp模板引擎
目录 1.模板引擎简介 2.环境准备 4.源码原理简介 SpringBoot系列之集成jsp模板引擎 @ 1.模板引擎简介 引用百度百科的模板引擎解释: 模板引擎(这里特指用于Web开发的模板引擎)是 ...
- SpringBoot日记——Thymeleaf模板引擎篇
开发通常我们都会使用模板引擎,比如:JSP.Velocity.Freemarker.Thymeleaf等等很多,那么模板引擎是干嘛用的? 模板引擎,顾名思义,是一款模板,模板中可以动态的写入一些参数, ...
- SpringBoot集成beetl模板快速入门
SpringBoot集成beetl模板快速入门 首次探索 beetl官方网址:http://ibeetl.com/ 创建SpringBoot工程(idea) 新建工程 选择创建Spring工程 书写包 ...
- SpringBoot系列: Pebble模板引擎
===============================Java 模板引擎选择===============================SpringBoot Starter项目向导中可选的J ...
- Springboot与Thymeleaf模板引擎整合基础教程(附源码)
前言 由于在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有做详细的介绍和记录,导致有些朋友用起来有些吃力,因此打算在接下来的时间里做一些基础整合的介绍,当然,可能也 ...
- 【Springboot】Springboot整合Thymeleaf模板引擎
Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...
随机推荐
- weblogic 12c重置console密码
su - oracle cd /u02/weblogic/user_projects/domains/base_domain source bin/setDomainEnv.sh cd /u02/ ...
- linux加域退域
realm list realm leave od.com realm join -U Administrator od.com
- Tomcat中session共享问题的简单解决办法
tomcat-redis-session-manager 使用redis配置tomcat共享session 结构图: 分析: 分布式web server集群部署后需要实现session共享,针对 to ...
- HDU 4099 大数+Trie
Revenge of Fibonacci Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 204800/204800 K (Java/ ...
- UVA-10765 Doves and bombs (双连通分量)
题目大意:给一个n个点的无向连通图,找出删除某个点后的连通块个数. 题目分析:统计一下每个节点属于几个双连通分量,若是割点,得到的便是答案,否则答案为1. 代码如下: # include<ios ...
- Hibernate入门_增删改查
一.Hibernate入门案例剖析: ①创建实体类Student 并重写toString方法 public class Student { private Integer sid; private ...
- iptables详解(6):iptables扩展匹配条件之’–tcp-flags’
如果你看过前文,那么你一定知道,前文已经对"tcp扩展模块"做过总结,但是只总结了tcp扩展模块中的"--sport"与"--dport"选 ...
- Mysql 表锁定的问题
下面的几个语句查询到,但如何定位到对应的进程,还需要学习这些表的结构. select * from information_schema.innodb_trx ## 当前运行的所有事务select * ...
- sql中exists,Intersect ,union 与union All的用法
熟练使用SQL Server中的各种用法会给查询带来很多方便.今天就介绍一下EXCEPT和INTERSECT.注意此语法仅在SQL Server 2005及以上版本支持. EXCEPT是指在第一个集合 ...
- bootstrap 获得轮播中的索引 getActiveIndex
今天想用bootstrap做一个轮播,当轮播滚到每张图的时候,在页面下面就显示相对应的内容,那么问题来了:我肯定需要知道当前活动(显示图片)的索引号,那么bootstrap的轮播组件要怎么获得这个索引 ...