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的更多相关文章

  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(转)

    添加依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>sp ...

  7. SpringBoot整合Freemarker+Mybatis

    开发工具 , 开始 新建工程 .选择Spring Initializr 下一步 下一步,选择需要的组件 ..改一下工程名,Finish ..目录结构 首先,修改pom文件 然后,将applicatio ...

  8. Spring-Boot整合freemarker引入静态资源css、js等

    一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...

  9. Spring-Boot整合freemarker引入静态资源css、js等(转)

    一.概述 springboot 默认静态资源访问的路径为:/static 或 /public 或 /resources 或 /META-INF/resources 这样的地址都必须定义在src/mai ...

  10. springboot整合freemarker模板引擎后在页面获取basePath绝对路径

    在项目中引用静态资源文件或者进行ajax请求时我们有时候会使用 ${basePath} ,其实这就是一种获取绝对路径的方式: 那么在springboot项目中要怎么配置才能使用 basePaht呢? ...

随机推荐

  1. finsh初步

    一. finsh在RT-Thread中被设计成一个独立的线程,它试图从外部设备中获得用户的输入,然后对用户命令进行解析执行. 正确使用finsh需要一个关联过程: rt_hw_board_init() ...

  2. Permission denied (publickey). fatal: Could not read from remote repository. Please make sure you have the correct access rights

    第一次提交遇到这样的情况,怎么回事呢,我在github上提交了ssh key 的啊. 排查先看看能不能解析, 1.先 ping https://github.com 把ip添加到 host :    ...

  3. consul eureka区别(来自Consul官网)

    consul 与 eureka Eureka是一个服务发现工具.该体系结构主要是客户端/服务器,每个数据中心有一组Eureka服务器,通常每个可用区域一个.通常Eureka的客户使用嵌入式SDK来注册 ...

  4. marquee标签跑马灯连续无空白播放效果 纯CSS(chrome opera有效)

    marquee似乎没有设置首尾相连播放的属性,内容滚动时总会留出一段marquee本身长度的空隙,某些情况下很不方便: 捣鼓了一会,得出一种解决办法,关键有两点: 1.将需要滚动的内容复制一份于同一行 ...

  5. java 调用cmd命令

    public class Port{ public static void main(String[] args) { Runtime runtime=Runtime.getRuntime(); tr ...

  6. markdown软件和网站

    网站:http://markdown.xiaoshujiang.com/ 软件: Moeditor:https://moeditor.org/ Remarkable:https://remarkabl ...

  7. selenium+testng+reportng+ant+jenkins集成日记

    1.新建一个项目 2.编写测试脚本 3.配置ant的build.xml脚本 4.集成到jenkins,并运行 1.新建项目   注意jdk的版本要一致 eclipse  Window --Prefer ...

  8. Gmail 邮件配置备忘

    1.smtp端口号不是默认的25,smtp的是587 2.必须设置“允许使用不够安全的应用” 其他的按照网上文档设置就好了

  9. asp.net源程序编译为dll文件并调用的实现过程

    很多时候,我们需要将.cs文件单独编译成.dll文件,这就需要使用csc命令将.cs文件编译成.dll动态链接库文件.具体的操作步骤如下: 打开命令窗口->输入cmd到控制台->cd C: ...

  10. 转载: vim使用技巧

    两篇很牛的vim使用技巧   来源: ChinaUnix博客 日期: 2009.07.06 10:18 (共有条评论) 我要评论   读本文之前请注意:1. 本文的目标是提供一些vim的使用技巧,利用 ...