Thymeleaf咋读!???

呵呵,是不是一脸懵逼。。。哥用我的大学四级英文知识告诉你吧:[θaimlif]。

啥玩意?不会音标?...那你就这样叫它吧:“赛母李府”,大部分中国人是听不出破绽的。。。。

Thymeleaf是啥?

四个字:页面模板(有道翻译结果)

就是在页面里面导入一些特有的标签和表达式,帮助我们更好地渲染页面

个人理解:

Thyme:百里香。leaf:叶子;

百里香是啥玩意?

经过上面的观察和分析,我感觉Thymeleaf的创作者是一个很有“生活”的人,我们看到上面图片上的百里香,一片一片的鲜翠的叶子很和谐的长在不同的枝头就好比我们的一个个HTML“叶面”分别存放在不同的文件夹下面,她们虽然在不同的枝头,但是她们的模样都很相似,这些相似点就是模板。。。

好了,哥敢用哥的一包花生米和一瓶啤酒打赌!!!如果你有幸阅读到哥的这篇文章,那么这绝逼是你见过对Thymeleaf最最最牛X的介绍。。。

官方介绍:https://www.thymeleaf.org/

Thymeleaf能够处理HTML,XML,JavaScript,CSS甚至纯文本。

看了上面的官方解释是不是更是一脸懵逼。。。那就不要纠结了,我们下面直接看她到底怎么用,用来干什么,这样你不就知道Thymeleaf是啥了吗

SpringBoot集成Thymeleaf:

首先为了大家看的不懵逼,我先展开一下整体项目结构:

1、pom.xml 添加 Thymeleaf 模板引擎

<!--thymeleaf模板-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>

2、application.properties 配置 Thymeleaf 信息

#下面是thymeleaf配置
# 启用缓存:建议生产开启
spring.thymeleaf.cache=false
# 建议模版是否存在
spring.thymeleaf.check-template-location=true
# Content-Type 值
spring.thymeleaf.servlet.content-type=text/html
# 是否启用
spring.thymeleaf.enabled=true
# 模版编码
spring.thymeleaf.encoding=utf-8
# 应该从解析中排除的视图名称列表(用逗号分隔)
spring.thymeleaf.excluded-view-names=
# 模版模式
spring.thymeleaf.mode=HTML5
# 模版存放路径
spring.thymeleaf.prefix=classpath:/templates/
# 模版后缀
spring.thymeleaf.suffix=.html

3、创建controller类,编写代码

我们创建ThymeleafTest.java,代码如下:

@Controller
@RequestMapping("/thymeleafTest")
public class ThymeleafTest {
@RequestMapping("/testThymeleaf")
public ModelAndView testThymeleaf(){
ModelAndView modelAndView=new ModelAndView("/thymeleaf");
modelAndView.addObject("user","任正非");
return modelAndView;
}
}

4、 创建模板,编写html代码

我们在resources/templates下创建index.html,代码如下:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>thymeleaf测试页面</title>
</head>
<body>
<h1 th:text="${user}"></h1>
</body>
</html>

启动项目然后访问:

至此thymeleaf就成功集成了,是不是很开心。。呵呵,但是你别高兴的太早了,,,此时你会发现你之前配置成功的JSP页面现在不能访问了

关于这个问题的解决请参考鄙人的另一篇博客:

https://www.cnblogs.com/luzhanshi/p/10925851.html

九、SpringBoot集成Thymeleaf模板引擎的更多相关文章

  1. SpringBoot集成Thymeleaf模板引擎

    简单介绍 目前在JavaEE领域有几中比较常用的模板引擎,分别是Jsp.Velocity.Freemarker.Thymeleaf,对Freemark语法不是特别熟悉,不过对于前端页面渲染效率来说,j ...

  2. 【Springboot】Springboot整合Thymeleaf模板引擎

    Thymeleaf Thymeleaf是跟Velocity.FreeMarker类似的模板引擎,它可以完全替代JSP,相较与其他的模板引擎,它主要有以下几个特点: 1. Thymeleaf在有网络和无 ...

  3. SpringBoot使用thymeleaf模板引擎

    (1).添加pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactI ...

  4. SpringBoot日记——Thymeleaf模板引擎篇

    开发通常我们都会使用模板引擎,比如:JSP.Velocity.Freemarker.Thymeleaf等等很多,那么模板引擎是干嘛用的? 模板引擎,顾名思义,是一款模板,模板中可以动态的写入一些参数, ...

  5. SpringBoot:2.SpringBoot整合Thymeleaf模板引擎渲染web视图

    在Web开发过程中,Spring Boot可以通过@RestController来返回json数据,那如何渲染Web页面?Spring Boot提供了多种默认渲染html的模板引擎,主要有以下几种: ...

  6. springboot整合Thymeleaf模板引擎

    引入依赖 需要引入Spring Boot的Thymeleaf启动器依赖. <dependency> <groupId>org.springframework.boot</ ...

  7. Springboot与Thymeleaf模板引擎整合基础教程(附源码)

    前言 由于在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有做详细的介绍和记录,导致有些朋友用起来有些吃力,因此打算在接下来的时间里做一些基础整合的介绍,当然,可能也 ...

  8. Springboot系列:Springboot与Thymeleaf模板引擎整合基础教程(附源码)

    前言 由于在开发My Blog项目时使用了大量的技术整合,针对于部分框架的使用和整合的流程没有做详细的介绍和记录,导致有些朋友用起来有些吃力,因此打算在接下来的时间里做一些基础整合的介绍,当然,可能也 ...

  9. SpringBoot使用thymeleaf模板引擎引起的模板视图解析错误

    Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as ...

随机推荐

  1. 已知两个int变量a、b,定义4个方法分别对变量a、b进行加减乘除运算,并测试结果。

    package com.fs.test; public class Test { public void aMethod(int a, int b) { int add = a + b;//*表示加法 ...

  2. Python3 A*寻路算法实现

    # -*- coding: utf-8 -*- import math import random import copy import time import sys import tkinter ...

  3. 通过三层交换机实现不同VLAN间的通信(案例+Cisco模拟器配置)

    如图,其中PC1和4位于销售部VLAN10,PC2和PC5位于市场部VLAN20,PC3和PC5位于财务部VLAN30,各主机的IP地址以及子网掩码已列出,下面将讲解如何配置利用三层交换机来实现不同V ...

  4. Matlab 中 Data-driven 风格的 API 设计

    设计 所谓 data-driven API,指的是用户可以把"操作"作为参数,传入函数,像下面这种: stream = dataStream('load', 'example.cs ...

  5. LeNet-5模型的keras实现

    import keras from keras.models import Sequential from keras.layers import Input,Dense,Activation,Con ...

  6. tensorflow 屏蔽 Log

    pip install alfred-py 在代码中加入 from alfred.dl.tf.common import mute_tf mute_tf()

  7. ps制作雾的效果

    制作雾的效果 方法一: 新建图层,将前景色设置为白色,背景色为黑色(因为雾的颜色是根据前景色决定的,也可根据这个原理制作火焰效果) 选择滤镜->渲染->云彩(也可选择其他效果的云彩) (选 ...

  8. javaScript事件--事件流

    一.事件 事件是文档或者浏览器窗口中发生的,特定的交互瞬间. 事件是用户或浏览器自身执行的某种动作,如click,load和mouseover都是事件的名字. 事件是javaScript和DOM之间交 ...

  9. linux lazarus 连接mssqlserver

    1 . 从https://www.freetds.org/ 下载驱动源文件 2. 参照 https://www.freetds.org/userguide/config.htm 内容编译 3. 启动l ...

  10. js-头部的下拉框出现与隐藏,注意加上stop??

    效果: 主要代码: