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. 01 语言基础+高级:1-8 File类与IO流_day10【缓冲流、转换流、序列化流】

    day10[缓冲流.转换流.序列化流] 主要内容 缓冲流 转换流 序列化流 打印流 教学目标 能够使用字节缓冲流读取数据到程序 能够使用字节缓冲流写出数据到文件 能够明确字符缓冲流的作用和基本用法 能 ...

  2. eclipse Java EE 与 Java 区别

    1. 综述 eclipse IDE 一般来说有三种可切换的模式 Java EE Java 调试 可直接下拉至底部看两者的比较. 2. Java Java 是带有用户界面的 基本IDE ,缺少数据库和w ...

  3. object detection模型转换成TensorFlow Lite,在Android应用

    环境 tensorflow = 1.12.0 bazel = 0.18.1 ubuntu = 16.04 python = 3.6.2 安装 bazel (0.18.1) 如果tensorflow是1 ...

  4. Maven--设置Http代理

    <settings> ... <proxies> <proxy> <id>my-proxy</id> <active>true& ...

  5. requset请求处理与BeanUtils封装

    HTTP: 概念:Hyper Text Transfer Protocol 超文本传输协议 传输协议:定义了,客户端和服务器端通信时,发送数据的格式 特点: 基于TCP/IP的高级协议 默认端口号:8 ...

  6. 2019年icpc上海网络赛 B Light bulbs (分块、差分)

    https://nanti.jisuanke.com/t/41399 题目大意: 有n个灯,m次操作,每次修改[l,r]内的灯,(off - on ,on - off),问最后有几盏灯亮着. 换种说法 ...

  7. 设置R更新源

    命令行设置R更新源 创建文件 R.home()/etc/Rprofile.site 设置更新源 local({r <- getOption("repos") r[" ...

  8. USB Reverse Tether (a dirty solution)

    Tether your android phone to your PC using USB cable could share your 3g Internet connection with PC ...

  9. 迅为iTOP-4418开发板编译Ubuntu

    Ubuntu 系统比较特殊,源码就是它的镜像.Ubuntu 系统通过解压的方式进行烧写,我们也可以通过配置解压出来的 Ubuntu 系统源码文件夹,来配置 Ubuntu 系统.然后通过打包压缩的方式来 ...

  10. PHP验证电子邮件-密码保护和随机密码

    验证邮箱: function isValidEmail($email){ return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a ...