引入Thymeleaf:

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<link th:href="@{bootstrap/css/bootstrap.css}" rel="stylesheet"/>
<link th:href="@{bootstrap/css/bootstrap-theme.css}" rel="stylesheet"/>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>
<title>Index</title>
</head>
<body>
Welcome!
</body>
</html>

引用Web静态资源:

<link th:href="@{bootstrap/css/bootstrap.css}" rel="stylesheet"/>
<link th:href="@{bootstrap/css/bootstrap-theme.css}" rel="stylesheet"/>

访问model(${}):

<div class="panel-body">
<span th:text="${person.name}"></span>
<span th:text="${person.age}"></span>
</div>

model迭代访问(th:each指令进行迭代,person为迭代元素,${people}访问people这个model):

<div class="panel panel-primary">
<div class="panel-heading">
<h3 class="panel-title">访问model列表</h3>
</div>
<div class="panel-body">
<ul class="panel-group">
<li class="list-group-item" th:each="person:${people}">
<span th:text="${person.name}"></span>
<span th:text="${person.age}"></span>
</li>
</ul>
</div>
</div>

数据判断(th:if指令进行判断,支持如 >、< 等类型的比较条件,同时支持SpringEL):

<div th:if="${not #lists.isEmpty(people)}">内容</div>

在JavaScript中访问model有些不同,形如 [[${}]]。通过th:inline,才可以访问model):

<script th:inline="javascript">
$(function () {
var person = [[${person}]];
console.log(person.name + "/" + person.age);
});
</script>

Thymeleaf 模板引擎技术的更多相关文章

  1. Spring Boot2(五):使用Spring Boot结合Thymeleaf模板引擎使用总结

    一.Thymeleaf概述 一般来说,常用的模板引擎有JSP.Velocity.Freemarker.Thymeleaf . SpringBoot推荐的 Thymeleaf – 语法更简单,功能更强大 ...

  2. Smarty模板引擎技术二

    Smarty模板引擎技术 内建函数 include_php内建函数 作用:载入一个php文件,将载入的文件的内容赋值给一个变量   注意:该内建函数只能在2.0中使用,如果使用的话,必须得实例化Sma ...

  3. Smarty模板引擎技术

    Smarty模板引擎技术 什么是模板引擎? 什么是Smarty模板引擎? 为何选择Smarty模板引擎? 如何使用Smarty模板引擎? 一.历史背景 场景一:回顾之前编写PHP项目的方式 //链接数 ...

  4. (二)SpringBoot基础篇- 静态资源的访问及Thymeleaf模板引擎的使用

    一.描述 在应用系统开发的过程中,不可避免的需要使用静态资源(浏览器看的懂,他可以有变量,例:HTML页面,css样式文件,文本,属性文件,图片等): 并且SpringBoot内置了Thymeleaf ...

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

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

  6. 三、thymeleaf模板引擎构建前台html, 后台使用 ModelAndView 和 Model 模型

    项目源码:https://github.com/y369q369/springBoot.git      ->     thymeleaf 私聊QQ: 1486866853 1.pom.xml中 ...

  7. SpringBoot使用thymeleaf模板引擎

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

  8. Spring Boot 2.0 整合Thymeleaf 模板引擎

    本节将和大家一起实战Spring Boot 2.0 和thymeleaf 模板引擎 1. 创建项目 2. 使用Spring Initlizr 快速创建Spring Boot 应用程序 3. 填写项目配 ...

  9. Thymeleaf模板引擎的初步使用

    在springboot中,推荐使用的模板引擎是Thymeleaf模板引擎,它提供了完美的Spring MVC的支持.下面就简单的介绍一下Thymeleaf模板引擎的使用. 在controller层中, ...

随机推荐

  1. 配置开发环境2——eclipse配置

    纯手动配置eclipse, Eclipse配置 配置工作空间的编码方式 General—Workspace:改成Other:UTF-8 配置property的编码方式 配置maven Window — ...

  2. 动手动脑-Java的方法重载

    例: Using overloaded methods public class MethodOverload {  public static void main(String[] args) {  ...

  3. A2W,W2A等的使用

    #include <atlbase.h> #include <atlconv.h> 代码块 { ...... USES_CONVERSION; CString TempDirP ...

  4. modelform添加属性

    暗暗啊

  5. Docker MySQL5.5镜像

    定制MySQL的镜像有个很大的难题:mysqld启动之前要初始化数据目录,5.5自带有空账号密码需要初始化. Dockerfile FROM centos # 拷贝需要的安装和MySQL初始脚本 CO ...

  6. docker 初步使用

    CentOS Linux release 7.2.1511 Docker version 17.03.1-ce 安装与启动 yum直接安装的docker版本较低,推荐这样安装: # 官方,可能网络连不 ...

  7. 【题解】Luogu P2787 语文1(chin1)- 理理思维

    原题传送门:P2787 语文1(chin1)- 理理思维 前置芝士:珂朵莉树 窝博客里对珂朵莉树的介绍 没什么好说的自己看看吧 珂朵莉树跑的飞快,但还是没有memset0小姐姐跑得快 操作1:暴力统计 ...

  8. linux下部署git服务器

    我这里用的是redhat7.4, 直接开始吧. 环境 服务端: Redhat7.4 + git(version 1.8.3.1) IP:192.168.137.168 客户端: win7 + git ...

  9. 程序连接oracle数据库问题Cannot create PoolableConnectionFactory ...

    报错: [ERROR] -- :: com.ipi.caee.InitServlet - 初始化数据加载异常 org.springframework.transaction.CannotCreateT ...

  10. mint-ui之toast使用(messagebox,indicator同理)

    toast为消息提示框,支持自定义位置.持续时间和样式. 一,注意事项 方法1   引入整个 Mint UI 组件,并需要再次单独引入Toast组件 Toast,它并不是一个全局变量,需要先引入 im ...