Spring Boot模板引擎(Thymeleaf) 2022-09-09 06:14 94阅读 0赞 # 背景 # 在前后端分离架构大行其道的当下,为什么Thymeleaf还未被淘汰,它到底有什么不可替代的优势? 1、易被对搜索引擎友好,它由服务端渲染,将页面直接输出到浏览器中,免去了动态DOM的生成环境,瞬间加载; 2、加载快。它生成的HTML文件通常只有几K,不需要用户长时间等待;特别是toC的产品,用户体验是极其重要的,通常1-2秒内页面没有打开,大家可能就直接关了; 3、上手快。对服务端开发人员友好,通常大家只需要掌握基础的HTML/CSS语法,不需要过多的学习即可开发页面。 # 如何在Spring Boot中使用 # 与其他模块的使用相同,只需要以下两步操作即可。 1、引入依赖; 2、配置(可选); ## 具体如下 ## **pom.xml** 引入依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> <version>2.3.12.RELEASE</version> </dependency> **application.yml** 基础配置 spring: thymeleaf: enabled: true encoding: UTF-8 prefix: classpath:/templates/ mode: HTML5 suffix: .html check-template-location: true cache: false servlet: content-type: text/html **resources/templates/layout.html** 模板文件 <!DOCTYPE html> <html lang="en" xmlns:th="http://www.thymeleaf.org"> <head> <meta charset="UTF-8"> <title th:text="${title}"></title> <style> body { font-size: 14px; line-height: 30px; } </style> </head> <body> <div> <div th:replace="::content">页面正文内容</div> </div> </body> </html> **resources/templates/index.html** 首页 <!DOCTYPE html> <html xmlns:th="http://www.thymeleaf.org" th:replace="layout"> <dl th:fragment="content"> <dt th:text="${title}"></dt> </dl> </html> # 基础语法 # **循环** <a th:each="item : ${categories}"> <a th:href="'c' + ${item.id}" th:text="${item.title}"></a> </a> **绑定对象** <div th:object="${user}"> <p>code: <span th:text="*{code}"></span></p> <p>name: <span th:text="*{name}"></span></p> <p>tel: <span th:text="*{tel}"></span></p> </div> **文件格式** <span th:text="|Welcome to our application, ${user.name}!|">
相关 Thymeleaf模板引擎 thymeleaf这样玩 1.springboot直接引入 2.配置thymeleaf视图解析器 3.编写模板html 选择变量表达式 谁践踏了优雅/ 2022年10月02日 04:55/ 0 赞/ 121 阅读
相关 Spring Boot模板引擎(Thymeleaf) 背景 在前后端分离架构大行其道的当下,为什么Thymeleaf还未被淘汰,它到底有什么不可替代的优势? 1、易被对搜索引擎友好,它由服务端渲染,将页面直接输出到浏览器中 短命女/ 2022年09月09日 06:14/ 0 赞/ 95 阅读
相关 Spring Boot集成Thymeleaf模板引擎 一、Thymeleaf 模板介绍 Spring Boot 推荐使用Thymeleaf 来代替传统开发中的JSP,那么什么是Thymeleaf 模板引擎呢?下面就来简单的介 不念不忘少年蓝@/ 2022年05月27日 23:19/ 0 赞/ 134 阅读
相关 Spring boot模板引擎 Thymeleaf SpringBoot推荐Thymeleaf模板引擎 语法更简单,功能更强大 ![这里写图片描述][70] 引入thymeleaf 客官°小女子只卖身不卖艺/ 2022年05月14日 04:57/ 0 赞/ 87 阅读
相关 Spring Boot 2.X 使用 Thymeleaf 模板引擎 在介绍 Thymeleaf 之前,首先要了解下 Spring Boot 怎么返回 String、resources/templates 和 resources/static 目 客官°小女子只卖身不卖艺/ 2022年03月28日 12:45/ 0 赞/ 102 阅读
相关 Spring Boot 学习 (七)springboot 集成 Thymeleaf 模板引擎 一、什么事是Thymeleaf Thymeleaf 是面向 Web 和独立环境的现代服务器端 Java 模板引擎,能够处理 HTML、XML、JavaScript、CSS 甚 àì夳堔傛蜴生んèń/ 2022年02月20日 15:57/ 0 赞/ 184 阅读
相关 Spring Boot 整合thymeleaf 模板引擎 Thymeleaf模板引擎是一个和Velocity、FreeMarker类似的模板引擎,它支持xml/xhtml/html5,且提供额外的模块与Spring MVC集成, 布满荆棘的人生/ 2022年01月06日 10:37/ 0 赞/ 174 阅读
相关 Spring Boot Web开发与thymeleaf模板引擎 简介: 使用Springboot应用,选中需要的模块, Spring已经默认将场景配置好了,只需在配置文件中少量配置就可以运行起来 自己编写业务代码 太过爱你忘了你带给我的痛/ 2021年11月09日 07:54/ 0 赞/ 233 阅读
相关 Spring Boot Thymeleaf 模板引擎的使用 Spring Boot 中可以支持很多模板引擎,`Thymeleaf` 是 Spring Boot 官方推荐使用的模板引擎,虽然在社区 `Thymeleaf` 的性能被许多人所 £神魔★判官ぃ/ 2021年11月01日 09:56/ 0 赞/ 274 阅读
相关 Spring Boot使用Thymeleaf模板引擎渲染web视图 Spring Boot开发Web应用 原创 [2018-04-][]03 宗野 [Spring Boot][] > [Spring Boot快 不念不忘少年蓝@/ 2021年09月15日 04:18/ 0 赞/ 308 阅读
还没有评论,来说两句吧...