【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf
========7、SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf =========================
1、SpringBoot Starter讲解
简介:介绍什么是SpringBoot Starter和主要作用
1、官网地址:https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#using-boot-starter
2、starter主要简化依赖用的
spring-boot-starter-web ->里面包含多种依赖
3、几个常用的starter
spring-boot-starter-activemq
spring-boot-starter-aop
spring-boot-starter-data-redis
spring-boot-starter-freemarker
spring-boot-starter-thymeleaf
spring-boot-starter-webflux
2、SpringBoot2.x常见模板引擎讲解和官方推荐使用
简介:介绍常用的SpringBoot2.x模板引擎和官方推荐案例
1、JSP(后端渲染,消耗性能)
Java Server Pages 动态网页技术,由应用服务器中的JSP引擎来编译和执行,再将生成的整个页面返回给客户端
可以写java代码
持表达式语言(el、jstl)
内建函数
JSP->Servlet(占用JVM内存)permSize
javaweb官方推荐
springboot不推荐 https://docs.spring.io/spring-boot/docs/2.1.0.BUILD-SNAPSHOT/reference/htmlsingle/#boot-features-jsp-limitations
2、Freemarker
FreeMarker Template Language(FTL) 文件一般保存为 xxx.ftl
严格依赖MVC模式,不依赖Servlet容器(不占用JVM内存)
内建函数
3、Thymeleaf (主推)
轻量级的模板引擎(负责逻辑业务的不推荐(ifelse多,上万条),解析DOM或者XML会占用多的内存)
可以直接在浏览器中打开且正确显示模板页面
直接是html结尾,直接编辑
xdlcass.net/user/userinfo.html
社会工程学
伪装
3、SpringBoot2.x整合模板引擎freemarker实战
简介:SpringBoot2.x整合模板引擎freemarker实战
1、Freemarker相关maven依赖
<!-- 引入freemarker模板引擎的依赖 -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-freemarker</artifactId>
</dependency>
2、Freemarker基础配置
# 是否开启thymeleaf缓存,本地为false,生产建议为true
spring.freemarker.cache=false
spring.freemarker.charset=UTF-8
spring.freemarker.allow-request-override=false
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.suffix=.ftl
#路径
spring.freemarker.template-loader-path=classpath:/templates/
3、建立文件夹
1)src/main/resources/templates/fm/user/
2)建立一个index.ftl
3)user文件夹下面建立一个user.html
4、简单测试代码编写和访问
4、SpringBoot2.x整合模板引擎thymeleaf实战
讲解:SpringBoot2.x整合模板引擎thymeleaf实战

package net.xdclass.demo.controller; import net.xdclass.demo.domain.ServerSettings; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/freemaker")
public class FreemakerController { @Autowired
private ServerSettings setting; @GetMapping("hello")
public String index(ModelMap modelMap){ modelMap.addAttribute("setting", setting); return "fm/index"; //不用加后缀,在配置文件里面已经指定了后缀
} }
freemakerController
官网地址:https://www.thymeleaf.org/doc/articles/thymeleaf3migration.html
1、thymeleaf相关maven依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
2、thymeleaf基础配置
#开发时关闭缓存,不然没法看到实时页面
spring.thymeleaf.cache=false
spring.thymeleaf.mode=HTML5
#前缀
spring.thymeleaf.prefix=classpath:/templates/
#编码
spring.thymeleaf.encoding=UTF-8
#类型
spring.thymeleaf.content-type=text/html
#名称的后缀
spring.thymeleaf.suffix=.html
3、建立文件夹
1)src/main/resources/templates/tl/
2)建立一个index.html
4、简单测试代码编写和访问
注意:$表达式只能写在th标签内部
快速入门:https://www.thymeleaf.org/doc/articles/standarddialect5minutes.html
import net.xdclass.demo.domain.ServerSettings; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; @Controller
@RequestMapping("/tyhmeleaf")
public class ThymeleafController { @Autowired
private ServerSettings setting; @GetMapping("hello")
public String index(){ return "index"; //不用加后缀,在配置文件里面已经指定了后缀
} @GetMapping("info")
public String admin(ModelMap modelMap){ modelMap.addAttribute("setting", setting); return "admin/info"; //不用加后缀,在配置文件里面已经指定了后缀
}
}
thyleafController
【SpringBoot】常用Starter介绍和整合模板引擎Freemaker、thymeleaf的更多相关文章
- SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf 4节课
1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...
- 小D课堂 - 零基础入门SpringBoot2.X到实战_第7节 SpringBoot常用Starter介绍和整合模板引擎Freemaker、thymeleaf_28..SpringBoot Starter讲解
笔记 1.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-b ...
- springboot配置server相关配置&整合模板引擎Freemarker、thymeleaf&thymeleaf基本用法&thymeleaf 获取项目路径 contextPath 与取session中信息
1.Springboot配置server相关配置(包括默认tomcat的相关配置) 下面的配置也都是模板,需要的时候在application.properties配置即可 ############## ...
- SpringBoot入门系列(四)整合模板引擎Thymeleaf
前面介绍了Spring Boot的优点,然后介绍了如何快速创建Spring Boot 项目.不清楚的朋友可以看看之前的文章:https://www.cnblogs.com/zhangweizhong/ ...
- SpringBoot第九集:整合JSP和模板引擎Freemarker/Thymeleaf(2020最新最易懂)
SpringBoot第九集:整合JSP和模板引擎(2020最新最易懂) 当客户通过前端页面提交请求后,我们以前是怎么做的?后端接收请求数据,处理请求,把响应结果交给模板引擎JSP,最后将渲染后的JSP ...
- Spring Boot整合模板引擎jsp
jsp也算是一种模板引擎吧.整合jsp前,先说一下运行SpringBoot项目的几种方式 1. 运行SpringBoot项目的几种方式 1.1 使用内嵌Tomcat运行项目 在IDE中右键运行启动类, ...
- SpringBoot系列:Spring Boot使用模板引擎FreeMarker
一.Java模板引擎 模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档. 在jav ...
- SpringBoot系列:Spring Boot使用模板引擎Thymeleaf
一.Java模板引擎 模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档. 在jav ...
- SpringBoot系列:Spring Boot使用模板引擎JSP
一.Java模板引擎 模板引擎(这里特指用于Web开发的模板引擎)是为了使用户界面与业务数据(内容)分离而产生的,它可以生成特定格式的文档,用于网站的模板引擎就会生成一个标准的HTML文档. 在jav ...
随机推荐
- Linux ssh下实现免密码登录
1.Linux 生成密钥 ssh-keygen -t rsa 进入“.ssh”会生成以下几个文件 id_rsa : 生成的私钥文件 id_rsa.pub : 生成的公钥文件 know_hosts : ...
- 两个python安装模块后 ImportError: No module named
问题描述:我的电脑安装了默认的arcgis自带的python,还自己安装了anaconda,所以有两个位置的python2.7 我自己使用arcgis的程序的时候,调用默认的那些是可以用的,但想使用d ...
- Mysql增量恢复
mysqldump增量恢复何时需要使用备份的数据? 备份最牛逼的层次,就是永远都用不上备份.--老男孩 不管是逻辑备份还是物理备份,备份的数据什么时候需要用?===================== ...
- phpldapadmin操作指导
1.在浏览器中打开http://IP/phpldapadmin 2. 点击[Login]按钮,输入管理员密码. 3.点击[创建新条目]. 4. 点击[Generic: Postfix Group]. ...
- SpringCloud注册中心环境搭建euraka
- vue 自定义组件使用v-model
<input v-model="something"> v-model指令其实是下面的语法糖包装而成: <input :value="something ...
- SocketServer模块,hmac模块验证client合法性
hmac模块: 1.模块初识: import hmac # h = hmac.new() #括号里要给它连个bytes类型,一个是自定义的secret_key,一个是你想进行加密的bytes # 密文 ...
- 使用Stickers拓展集成iMessage简单功能
添加一个target,选择Stickers拓展: 然后就会出现iMessage的文件夹:添加你需要的iMessage图片,这里图片遵循下面的要求: Small: 100 x 100 pt @3x sc ...
- Android开发 ---多线程操作:Handler对象,消息队列,异步任务下载
效果图: 1.activity_main.xml 描述:定义了六个按钮 <?xml version="1.0" encoding="utf-8"?> ...
- secondPage
写的第二个页面,参照着别人的代码,网上找寻自己需要的标签,每个小地方都得试许多次才能明白标签的正确使用方法,自己动手写出来一个页面虽然超级粗糙,但是挺有收获的. <!DOCTYPE html&g ...