springboot-整合freemarker
freemarker是一个页面模板引擎。用springboot整合freemarker的方式如以下步骤:
1.在创建springboot的项目的时候,选择freemarker的组件,或者自己手动在maven中添加库依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2.在application.aproperties中添加相应的配置:
spring.freemarker.charset=UTF-
spring.freemarker.content-type=text/html; charset=utf-
spring.freemarker.expose-request-attributes=true
spring.freemarker.allow-session-override=true
spring.freemarker.expose-spring-macro-helpers=true
spring.freemarker.suffix=.ftl spring.freemarker.settings.datetime_format=yyyy-MM-dd HH:mm:ss
spring.freemarker.settings.default_encoding=UTF-
3.新建一个controller类来访问
@Controller
public class HelloController { @Autowired
private UserService userService; @RequestMapping("hello")
public String hello(ModelMap modelMap){
List<User> users = userService.getUsers();
User one = users.get();
modelMap.put("user", one);
return "hello"; //freemarker文件的名字 } }
4.新建一个ftl页面文件
<!DOCTYPE html>
<html lang="en-US">
<header></header>
<body>hello,${user.id}</body>
</html>
Freemarker的结构化布局
1.抽取header、footer、nav、js、分页,利用freemarker提供的宏,将这些部分定义成宏。
2.页面中引入header、footer
3.编写页面中自定义的部分
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(转)
添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...
- 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呢? ...
随机推荐
- 挑战:万能的slash! 判断js中“/”是正则、除号、注释?
很久以前在其它地方就探讨和关注过这个问题,但都没有满意的解答. 看了zjfeihu 的帖子: <前端代码加亮插件(html,jss,css),支持即时加亮,运行代码>,再次提出这个比较经典 ...
- sql limit offset 区别
select * from table limit 2,1; //含义是跳过2条取1条数据,即读取第3条数据 select * from table limit 2 ...
- easyui最简单的左右布局实现,及tab的右键菜单实现
发现最近有些人问用JQuery easyui要怎么实现左右结构的布局.就是点击左边的菜单在右边的tab中打开.其实easyui要实现这种布局很简单,只需要简单的几行代码就ok了. 特意做了一个小小的d ...
- python 字符串格式化 ( 百分号 & format )
Python的字符串格式化有两种方式: 百分号方式.format方式 百分号的方式相对来说比较老,而format方式则是比较先进的方式,企图替换古老的方式,目前两者并存. ----百分号 tpl = ...
- spring-security+hibernate4+quartz实现的心跳检测项目(转 收藏)
转自:http://www.52itstyle.com/thread-27470-1-1.html HeartBeat. ~2 Z8 U! ?8 r心跳检测各类应用服务器(如Tomcat,Jetty) ...
- PHP 如何成长 (收藏自:http://www.cnblogs.com/try-better-tomorrow/p/6964036.html)
原文题目为<php程序员学C/C++>,不过我觉得说是提升自己比较合适. 身边有几个做PHP开发的朋友,因为面试,也接触到不少的PHP工程师,他们常疑虑自己将来在技术上的成长与发展,我常给 ...
- unintest基础1
import unittest class Testfunc(unittest.TestCase): def testfunc(self): print('testfunc1') def testfu ...
- httpclient设置proxy与proxyselector
If single proxy for all targets is enough for you: HttpComponentsClientHttpRequestFactory clientHttp ...
- FW ImageMagick
ExploitFixes ImageMagick < 6.9.3-9 - Multiple Vulnerabilities 2016-05-04 22:05:53 Nikolay Ermishk ...
- java爬虫-简单爬取网页图片
刚刚接触到“爬虫”这个词的时候是在大一,那时候什么都不明白,但知道了百度.谷歌他们的搜索引擎就是个爬虫. 现在大二.再次燃起对爬虫的热爱,查阅资料,知道常用java.python语言编程,这次我选择了 ...