一、SpringBoot整合freemarker:

  1.引入freemarker模板依赖:

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>

  2.配置application.properties:

#freemarker 静态资源配置
#设定ftl文件路径
spring.freemarker.template-loader-path=classpath:/templates
#关闭缓存,还是刷新,上线生产环境需要改为true
spring.freemarker.cache=false
spring.freemarker.charset=utf-
spring.freemarker.check-template-location=true
spring.freemarker.content-type=text/html
spring.freemarker.expose-request-attributes=true
spring.freemarker.expose-session-attributes=true
spring.freemarker.request-context-attribute=request
spring.freemarker.suffix=.ftl

  3.在resources目录下建个目录叫templates,在这个目录下新建一个以.ftl结尾的文件,并且将html代码复制进去,在controller层返回这个视图

二、SpringBoot整合thymeleaf

  1.引入thymeleaf模板依赖

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>

  2.配置application.properties:

#thymeleaf静态资源配置
spring.thymeleaf.prefix=classpath:/templates/
spring.thymeleaf.suffix=.html
spring.thymeleaf.mode=HTML5
spring.thymeleaf.encoding=UTF-
spring.thymeleaf.content-type=text/html
#关闭缓存,即时刷新,上线生产环境需要改为true
spring.thymeleaf.cache=true

  3.在resoureces下新建个目录templates在里面编写html文件,具体的thymeleaf标签语法这里就不做介绍了。

SpringBoot整合模板引擎的更多相关文章

  1. springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息

    1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...

  2. 【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf

    ========7.SpringBoot常用Starter介绍和整合模板引擎Freemaker.thymeleaf ========================= 1.SpringBoot Sta ...

  3. SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课

    1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...

  4. SpringBoot入门系列(四)整合模板引擎Thymeleaf

    前面介绍了Spring Boot的优点,然后介绍了如何快速创建Spring Boot 项目.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/ ...

  5. 小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_28..SpringBoot Starter讲解

    笔记 1.SpringBoot Starter讲解     简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-b ...

  6. Spring Boot整合模板引擎jsp

    jsp也算是一种模板引擎吧.整合jsp前,先说一下运行SpringBoot项目的几种方式 1. 运行SpringBoot项目的几种方式 1.1 使用内嵌Tomcat运行项目 在IDE中右键运行启动类, ...

  7. springboot集成模板引擎freemarker和thymeleaf

    freemarkder和thymeleaf都是java的模板引擎,这里只介绍这两种模板引擎如何在sprongboot中配置: 1. freemarkder 1.1 在pom.xml中添加依赖包 < ...

  8. SpringBoot:模板引擎 thymeleaf、ContentNegotiatingViewResolver、格式化转换器

    目录 模板引擎 thymeleaf ContentNegotiatingViewResolver 格式化转换器 模板引擎 thymeleaf.ContentNegotiatingViewResolve ...

  9. SpringBoot系统列 5 - 接口版本控制、SpringBoot FreeMarker模板引擎

    接着上篇博客的代码继续写 1.接口版本控制 一个系统上线后会不断迭代更新,需求也会不断变化,有可能接口的参数也会发生变化,如果在原有的参数上直接修改,可能会影响线上系统的正常运行,这时我们就需要设置不 ...

随机推荐

  1. 使用minukube部署kubernetes admission webhook实现etcd pod安全删除

    本需求来自于一道面试题

  2. Linux中文件MD5校验

    md5sum命令用于生成文件的md5数字摘要,并可以验证文件内容是否发生了改变,间接地还可以检验两个文件内容是否完全相同.因为md5sum是读取文件内容来计算校验码的,因此只能验证文件内容,而无法验证 ...

  3. 关于VS Code使用注意

    1]:初次使用vs code或多或少有些问题.比如不小心把最左边的这四个快捷按钮消失.,直接按 alt+v  选择[显示活动板]就行了 2]:修改界面语言   快捷键ctrl+shift+p   [修 ...

  4. Tomcat 8005/8009/8080/8443端口的作用

    --关闭tomcat进程所用.当执行shutdown.sh关闭tomcat时就是连接8005端口执行“SHUTDOWN”命令--由此,我们直接telnet8005端口执行“SHUTDOWN”(要大写, ...

  5. sql-索引的作用(超详细)

    (一)深入浅出理解索引结构 实际上,您可以把索引理解为一种特殊的目录.微软的SQL SERVER提供了两种索引:聚集索引(clustered index,也称聚类索引.簇集索引)和非聚集索引(nonc ...

  6. Tree View控件(添加,移除,设置图标)

    添加 父节点,并为父节点添加子节点 private void button1_Click(object sender, EventArgs e) { TreeNode tn1 = treeView1. ...

  7. [Linux] Linux的环境变量

    环境变量可以被系统,用户,shell以及其他程序来设定 登录系统后,系统读取/etc/profile 文件,设置环境变量,如果没有就跳过 检查主目录(/root)的.profile文件,推荐去这个文件 ...

  8. mysql 关联查询技巧

    废话不多说,直接进入正题 #数据准备 班级表class: CREATE TABLE `class` ( `class_no` ) unsigned zerofill NOT NULL AUTO_INC ...

  9. 46.Linux-创建rc红外遥控平台设备,实现重复功能(2)

    上章链接:46.Linux-分析rc红外遥控平台驱动框架,修改内核的NEC解码函数BUG(1) 在上章分析了红外platform_driver后,已经修改bug后,接下来我们自己创建一个红外platf ...

  10. mybatis_03_ mapper代理方式实现MyBatis的Dao编写

    不是用mapper代理方式也能够实现,但是不推荐 Mapper代理的开发方式,程序员只需要编写mapper接口(相当于dao接口)即可.Mybatis会自动的为mapper接口生成动态代理实现类. 不 ...