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. TCP的三次握手与四次挥手理解及面试题

    TCP的三次握手与四次挥手理解及面试题(很全面) 转载自:https://blog.csdn.net/qq_38950316/article/details/81087809 本文经过借鉴书籍资料.他 ...

  2. 简单告诉你-"border:0"与"border:none"的区别

    "border:0"与"border:none"的差异主要体现在性能差异和兼容差异.1.性能差异"border:0"表示把border定义为 ...

  3. Intellij IDEA 最全实用快捷键整理

    正文前: 1. IDEA内存优化(秒开的快感!!) 因机器本身的配置而配置: \IntelliJ IDEA8\bin\idea.exe.vmoptions // (根据你的配置变大!!) ------ ...

  4. 安卓-去除ActionBar的方法

    今天做一个播放器项目,由于要去除ActionBar,纠结好久,原来这么简单 记录一下 只需要修改AndroidManifest.xml文件中的主题即可 <application android: ...

  5. (转)JAVA socket 进行十六进制报文交互测试

    import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io. ...

  6. ubuntu 安装nginx redis dotnet

    1 安装nginx sudo apt-get update sudo apt-get install nginx 配置文件 /etc/nginx/nginx.conf 2 安装redis sudo a ...

  7. u-boot include目录 gd_t结构体 如何关联芯片指定的目录

    1 u-boot /u-boot-2018.07-fmxx/include/config.h /* Automatically generated - do not edit */#define CO ...

  8. Markdown小结

    Markdown标题 以# (#号加空格)开头的行会被视为标题,根据#的数量分为一到六级标题 # 一级标题 ## 二级标题 … ###### 六级标题 Markdown 水平线 一行由三个以上连续的减 ...

  9. asp.net mvc + vue.js + axios.js

    1.新建一个 MVC 应用程序 2.右键解决方案 添加VUE 3.搜索vue 1.安装axios.js ,用于数据请求,get , post axios

  10. Notepad++技巧

    1 正则表达式的查找和替换,例如删除每行开始的数字ctrl+H, ^\d\d\d:null 2 删除所有的空行: TextFX插件->Edit->Delete Blank Lines 3 ...