专注Java教育14年 全国咨询/投诉热线:400-8080-105
动力节点LOGO图
始于2009,口口相传的Java黄埔军校
首页 学习攻略 Java学习 新课上线,动力节点Thymeleaf服务器模板引擎

新课上线,动力节点Thymeleaf服务器模板引擎

更新时间:2021-05-17 14:12:52 来源:动力节点 浏览1519次

Thymeleaf 是一款用于渲染 XML/XHTML/HTML5 内容的模板引擎。它类似我们之前使用的 JSP、FreeMaker 等模版,它也可以轻易与 Spring MVC 等 Web 框架进行集成作为 Web 应用的模板引擎。同时Thymeleaf得到了Spring Boot官方对的推荐使用,同时也是未来的一个趋势。

Thymeleaf服务器

与其它模板引擎相比,Thymeleaf最大的特点是能够直接在浏览器中打开并正确显示模板页面,而不需要启动整个Web应用。

Thymeleaf的优势在于

1. 以html的属性出现,保证html的完整语法结构不被破坏;

2. 浏览器可直接预览模板文件,无需服务器端支持;

3. 提供了大量内置对象,内置工具类;

4. 语法简单,学习难度低;

5. 支持html,js,raw等多种模板类型;

Thymeleaf快速入门

1. 在使用Thymeleaf之前,首先在pom.xml文件导入依赖

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

2. resource目录下的templates目录新建一个html页面test.html(另外Thymeleaf默认的页面文件后缀是.html)

编写controller层

package com.markjava.controller;import org.springframework.stereotype.Controller;import org.springframework.ui.Model;import org.springframework.web.bind.annotation.RequestMapping;@Controllerpublic class UserController {@RequestMapping("/hello") public String test(Model model) { model.addAttribute("name","MarkerJava"); return "test"; }

然后打开浏览器访问localhost:8080/hello运行会获取到MarkerJava

注:

th:text在th后面加上一个冒号,并附加特定的字符组合,这个thymeleaf定义的占位符是构建thymeleaf页面的基础。

th:text="${name}"中的${}是个占位符${}是个占位符

如果大家还是没有看懂,不太了解的话,可以跟着动力节点的Thymeleaf基础教程来学习,这样更能直观的了解,从课程适合在后台应用,以及各种管理类系统中使用。带你一步一步详解讲解Thymeleaf模板引擎技术,全面掌握Thymeleaf模板技术,并在实际项目开发中得心应手使用Thymeleaf模板技术。

 课程目录:

课程目录:

第一章Thymeleaf小试牛刀

1-1 thymeleaf-模板工作方式

1-2 thymeleaf-文档

1-3 thymeleaf-第一个例子

1-4 thymeleaf-模板使用数据

1-5 thymeleaf-使用模板文件

1-6 thymeleaf-设置模板前缀后缀

1-7 thymeleaf-springboot环境搭建

1-8 thymeleaf-测试springboot中使用模板

第二章Thymeleaf语法

2-1 thymeleaf-变量表达式基本语法-1

2-2 thymeleaf-变量表达式基本语法-2

2-3 thymeleaf-链接表达式

2-4 thymeleaf-链接表达式传参数

2-5 thymeleaf-国际化介绍

2-6 thymeleaf-自定义LocalResolver

2-7 thymeleaf-国际化模板定义

2-8 thymeleaf-调式国际化

2-9 thymeleaf-文本表达式

2-10 thymeleaf-数字表达式

2-11 thymeleaf-布尔表达式

2-12 thymeleaf-null和空字符串

2-13 thymeleaf-逻辑表达式

2-14 thymeleaf-三元运算符-1

2-15 thymeleaf-三元运算符-2

2-16 thymeleaf-设置属性值

2-17 thymeleaf-attr设置任意属性值

2-18 thymeleaf-设置属性值

2-19 thymeleaf-同时设置多个属性值

2-20 thymeleaf-boolean设置

2-21 thymeleaf-设置标签体文本

2-22 thymeleaf-循环each(1)

2-23 thymeleaf-each循环普通Map

2-24 thymeleaf-each循环ListMap

2-25 thymeleaf-each循环数组

2-26 thymeleaf-each循环给Select组件添加数据

2-27 thymeleaf-each循环的状态变量

2-28 thymeleaf-if使用

2-29 thymeleaf-unless使用

第三章Thymeleaf模板引用

3-1 thymeleaf-模版的介绍

3-2 thymeleaf-模版insert使用

3-3 thymeleaf-函数模版和当前页面中定义模版

3-4 thymeleaf-使用id引用模版

3-5 thymeleaf-replace和include的对比

3-6 thymeleaf-常用insert-replace

3-7 thymeleaf-re删除

3-8 thymeleaf-re其它的范围值

3-9 thymeleaf-动态指定模版名称

3-10 thymeleaf-inline在js中获取数据

3-11 thymeleaf-inline和text的比较使用

3-12 thymeleaf-禁用内联

3-13 thymeleaf-局部变量

第四章Thymeleaf内置对象

4-1 thymeleaf-内置工具类

4-2 thymeleaf-内置工具类日期和string

4-3 thymeleaf-内置对象#request

4-4 thymeleaf-内置对象#session和#servletContext

4-5 thymeleaf-快捷对象param

4-6 thymeleaf-快捷对象session和application

还处于初学者的同学,能力上可能还学不到这些,不过没关系,动力节点还有针对初学者进阶准备了其它适合的Java视频课程,等你跟上进度后,在看这套教程就非常简单,好学啦。

提交申请后,顾问老师会电话与您沟通安排学习

免费课程推荐 >>
技术文档推荐 >>