1、常用标签:

  • 使用thymeleaf模板,首要在html中引入:
<html xmlns:th="http://www.thymeleaf.org">
  • 引入css、js

  引入css,使用标签th:href="@{路径}"

  引入js,使用标签th:src="@{路径}"

    <link rel="stylesheet" th:href="@{/static/ace_admin_v1.4.0/assets/css/ace-ie.css}"/>

    <script th:src="@{/static/ace_admin_v1.4.0/assets/js/ace-extra.js}"></script>
  • th:text 文本替换

  <p th:text="${collect.description}">description</p>

  • th:value 属性赋值

  <input th:value = "${user.name}" />

  • th:each迭代循环
<tr th:each="user,userStat: ${pageInfo.rows}">
<td th:text="${userStat.count}"/>
<td th:text="${user.suName}"/>
<td th:text="${user.suEmail}"/>
<td th:text="${user.suPhone}"/>
<td th:switch="${user.suState}">
<span th:case="0" class="label label-sm label-warning">未激活</span>
<span th:case="1" class="label label-sm label-success">已激活</span>
<span th:case="2" class="label label-sm label-inverse arrowed-in">已注销</span>
</td>
<td>
<div class="hidden-sm hidden-xs action-buttons">
<a class="green" href="#">
<i class="ace-icon fa fa-pencil bigger-130"></i>
</a> <a class="red" href="#">
<i class="ace-icon fa fa-trash-o bigger-130"></i>
</a>
</div>
</td>
</tr>
userStat称作状态变量,<td th:text="${userStat.count}"/>代表序号
属性有:

    index:当前迭代对象的index(从0开始计算)
    count: 当前迭代对象的index(从1开始计算)
    size:被迭代对象的大小
    current:当前迭代变量
    even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
    first:布尔值,当前循环是否是第一个
    last:布尔值,当前循环是否是最后一个

  • th:onclick 点击事件,传参
th:onclick="'javascript:splitPageLink(\''+${url}+'\',\''+${index}+'\')'"

2、与Spring MVC集成

  • 引入依赖
    <!--thymeleaf-->
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf</artifactId>
<version>${thymeleaf-version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.thymeleaf/thymeleaf-spring4 -->
<dependency>
<groupId>org.thymeleaf</groupId>
<artifactId>thymeleaf-spring4</artifactId>
<version>${thymeleaf-version}</version>
</dependency>
  • spring配置文件
    <!-- TemplateResolver <- TemplateEngine <- ViewResolver -->
<!-- 使用thymeleaf解析,切记要设置编码 -->
<bean id="templateResolver" class="org.thymeleaf.spring4.templateresolver.SpringResourceTemplateResolver">
<property name="prefix" value="/WEB-INF/page/"/>
<property name="suffix" value=".html"/>
<property name="templateMode" value="HTML5" />
<property name="cacheable" value="false"/>
<!-- 解决中文乱码 -->
<property name="characterEncoding" value="UTF-8" />
</bean>
<!-- Thymeleaf Template Engine (Spring4-specific version) -->
<bean id="templateEngine" class="org.thymeleaf.spring4.SpringTemplateEngine">
<property name="templateResolver" ref="templateResolver"/>
</bean> <!-- Thymeleaf View Resolver - implementation of Spring's ViewResolver interface -->
<bean class="org.thymeleaf.spring4.view.ThymeleafViewResolver">
<property name="templateEngine" ref="templateEngine" />
<!-- 解决中文乱码 -->
<property name="characterEncoding" value="UTF-8" />
</bean>

Thymeleaf模板笔记的更多相关文章

  1. thymeleaf模板的使用(转)

    作者:纯洁的微笑 出处:http://www.ityouknow.com/ 在上篇文章springboot(二):web综合开发中简单介绍了一下thymeleaf,这篇文章将更加全面详细的介绍thym ...

  2. thymeleaf模板引擎简介

    一:thymeleaf 学习笔记---http://www.blogjava.net/bjwulin/articles/395185.html thymeleaf是一个支持html原型的自然引擎,它在 ...

  3. Thymeleaf 模板的使用

    Thymeleaf是现代化服务器端的Java模板引擎,不同与JSP和FreeMarker,Thymeleaf的语法更加接近HTML,并且也有不错的扩展性.详细资料可以浏览官网.本文主要介绍Thymel ...

  4. vert.x学习(三),Web开发之Thymeleaf模板的使用

    在vert.x中使用Thymeleaf模板,需要引入vertx-web-templ-thymeleaf依赖.pom.xml文件如下 <?xml version="1.0" e ...

  5. JavaEE开发之SpringBoot整合MyBatis以及Thymeleaf模板引擎

    上篇博客我们聊了<JavaEE开发之SpringBoot工程的创建.运行与配置>,从上篇博客的内容我们不难看出SpringBoot的便捷.本篇博客我们继续在上篇博客的基础上来看一下Spri ...

  6. thymeleaf模板引擎调用java类中的方法(附源码)

    前言 <Docker+SpringBoot+Mybatis+thymeleaf的Java博客系统开源啦> 由于开源了项目的缘故,很多使用了My Blog项目的朋友遇到问题也都会联系我去解决 ...

  7. (二)springboot整合thymeleaf模板

    在我们平时的开发中,用了很久的jsp作view显示层,但是标签库和JSP缺乏良好格式的一个副作用就是它很少能够与其产生的HTML类似.所以,在Web浏览器或HTML编辑器中查看未经渲染的JSP模板是非 ...

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

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

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

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

随机推荐

  1. Android studio2.2 app:transformNative_libsWithStripDebugSymbolForDebug

    开始搜到的问题相关链接: http://blog.csdn.NET/doumingliangdendsc/article/details/52595317 https://www.oschina.ne ...

  2. [LC] 51. N-Queens

    Given an integer n, return all distinct solutions to the n-queens puzzle. Each solution contains a d ...

  3. 单个body|简单解释|复杂解释|反面解释

    单个body有三种方法简单解释.复杂解释和反面解释 ========================================================================== ...

  4. diverta 2019 Programming Contest 2自闭记

    A 签到(a-b problem不用贴了吧,以后atcoder小于300分题均不贴代码) B 发现选择的p,q一定是其中两点间的距离,于是可以O(n2)枚举两点,再O(n2)判断,其实可以做到O(n3 ...

  5. Excel VBA发送Email时自动允许Outlook安全对话框

    在Outlook的宏安全性设置如果选择了“为所有宏提供通知” 并且,在[编程访问]中选择了“总是向我发出警告” 在其他VBA中创建邮件过程中,如果修改Recipients或者执行Send方法,都会弹出 ...

  6. 放贷额度相关的ROI计算

    违约模型得到概率估计, 将概率值划分5档, 每一档确定一个授信系数 新的授信 = 每月收入* 授信系数 - 老的授信 计算新增授信额度 计算余额损失

  7. SpringBoot项目启动之前操作,启动之后操作

    1.在Bean对象初始化之前可以做的操作 @Component public class InitBean implements BeanDefinitionRegistryPostProcessor ...

  8. 1)PHP基础介绍

    1.php基础介绍: Perssonal Home Page  ====>PHP 2.应用范围 · web服务器脚本语言 命令行脚本语言     应用程序图形界面 3.PHP运行环境 PHP解释 ...

  9. BTree

    hash.平衡二叉树.BTree.B+tree的区别 https://blog.csdn.net/qq_40673786/article/details/90082444 联合索引在B+树上的结构介绍 ...

  10. PAT甲级——1077.Kuchiguse(20分)

    The Japanese language is notorious for its sentence ending particles. Personal preference of such pa ...