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在有网络和无 ...
随机推荐
- Mysql解压版配置环境等
背景故事:安装版的mysql和我的本本有仇,最后一步老卡死 1.首先先把下载好的压缩包解压,如下图:
- ansible modules开发(一)
一 模块说明 官方是否有提供的类似功能模块? 可从下面两个连接确定官方提供的模块,以免重复造轮子 官方已发布的模块 http://docs.ansible.com/ansible/modules.ht ...
- BGP&RIP
策略路由是2000之前 如果不通检查是否有相互影响的策略 BGP 25端 查看 25是上端起lan 地址是172.100.1.254 互联158是下端起wan 172.100.1.158 25的内 ...
- 2793 [Poi2012]Vouchers
我们直接模拟就可以了= = now[x]表示x的倍数已经取到x * i了,于是每次读入x,直接向上枚举x个没取过的数即可. /************************************* ...
- 转载:【Oracle 集群】RAC知识图文详细教程(二)--Oracle 集群概念及原理
文章导航 集群概念介绍(一) ORACLE集群概念和原理(二) RAC 工作原理和相关组件(三) 缓存融合技术(四) RAC 特殊问题和实战经验(五) ORACLE 11 G版本2 RAC在LINUX ...
- nginx的编译,和简单的配置问题
反向代理常见的lvs.haproxy. 缓存服务常见的.squid.vanish.常见的前端缓存.Apache是多进程的web服务器,Nginx是多线程的web服务器. Nginx的特点,对静态能力强 ...
- poj2400
题解: 最少平均分值是等于最佳匹配的权值和除上一个总的点数2*n 注意输入反过来 代码: #include<cstdio> #include<cstring> #include ...
- hdu1507
题解: 二分图最大匹配 建边和第一题差不多 每两个相邻的建边 然后输出方案 代码: #include<cstring> #include<cmath> #include< ...
- fzu Problem 2275 Game(kmp)
Problem 2275 Game Accept: 62 Submit: 165Time Limit: 1000 mSec Memory Limit : 262144 KB Proble ...
- Alpha冲刺(2/10)
前言 队名:拖鞋旅游队 组长博客:https://www.cnblogs.com/Sulumer/p/9960487.html 作业博客:https://edu.cnblogs.com/campus/ ...