一、引用命名空间 <html xmlns:th="http://www.thymeleaf.org">

在html中引入此命名空间,可避免编辑器出现html验证错误,虽然加不加命名空间对Thymeleaf的功能没有任何影响。

二. 取值

  #{home.welcome} --  访问数据

#{home.welcome(${session.user.name})}  -- 格式化数据 当 home.welcome 为 "abcdegf{0}"  类似这种内容时。(多个参数以逗句分隔)。

  ${today} --- 访问变量

  日期的输出 <span th:text="${#calendars.format(today,'dd MMMM yyyy')}">13 May 2011</span>

三、访问对象

${param.x} 返回名为x 的 request参数。(可能有多个值)

${session.x} 返回名为x的Session参数。

${application.x} 返回名为 servlet context 的参数 

  星号语法

  <div th:object="${session.user}">
    <p>Name: <span th:text="*{firstName}">Sebastian</span>.</p>
    <p>Surname: <span th:text="*{lastName}">Pepper</span>.</p>
    <p>Nationality: <span th:text="*{nationality}">Saturn</span>.</p>
  </div>

  输出URL

<a href="product/list.html" th:href="@{/product/list}">Product List</a>

<a href="details.html" th:href="@{/order/{orderId}/details(orderId=${o.id})}">view</a>

  直接输出内容

  <span th:text="'working web application'"> -- 输出字符

  <span th:text="2013 + 2">  -- 输出数据表达式

  <div th:if="${user.isAdmin()} == false">  --输出布尔表达式

  <span th:text="'Welcome to our application, ' + ${user.name} + '!'"> -- 带变量的

  条件表达式

  <tr th:class="${row.even}? 'even' : 'odd'">
  ...  
  </tr>

循环输出的语法

6.1 基本循环

<tr th:each="prod : ${prods}">

<td th:text="${prod.name}">Onions</td>
     <td th:text="${prod.price}">2.41</td>
     <td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
</tr>

循环状态的使用

  <table>
  <tr>
  <th>NAME</th>
  <th>PRICE</th>
  <th>IN STOCK</th>
  </tr>
  <tr th:each="prod,iterStat : ${prods}" th:class="${iterStat.odd}? 'odd'">
  <td th:text="${prod.name}">Onions</td>
  <td th:text="${prod.price}">2.41</td>
  <td th:text="${prod.inStock}? #{true} : #{false}">yes</td>
  </tr>
  </table>

关于状态的其它信息的使用详细参考:http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#keeping-iteration-status

  更多详情的说明和规则请参见:http://www.thymeleaf.org/doc/tutorials/3.0/usingthymeleaf.html#introducing-thymeleaf

thymeleaf html5的更多相关文章

  1. SpringMvc+thymeleaf+HTML5中文乱码问题

    SpringMvc+thymeleaf+HTML5环境下遇到中文乱码...... 按照以往经验逐个排查,开发环境统一为utf-8编码,服务器也配置了编码过滤器,tomcat也是utf-8编码.前台页面 ...

  2. Spring boot配合Spring session(redis)遇到的错误

    背景:本MUEAS项目,一开始的时候,是没有引入redis的,考虑到后期性能的问题而引入.之前没有引用redis的时候,用户登录是正常的.但是,在加入redis支持后,登录就出错!错误如下: . __ ...

  3. SpringBoot接口服务处理Whitelabel Error Page(转)

    To switch it off you can set server.error.whitelabel.enabled=false http://stackoverflow.com/question ...

  4. Whitelabel Error Page 专题

    Spring boot为错误视图提供了如下错误属性:timestamp:错误发生的时间status:HTTP状态码error:错误原因exception:异常的类名message:异常消息(如果这个错 ...

  5. SpringBoot接口服务处理Whitelabel Error Page

    转载请注明来源:http://blog.csdn.net/loongshawn/article/details/50915979 <SpringBoot接口服务处理Whitelabel Erro ...

  6. 【Thymeleaf】Thymeleaf模板对没有结束符的HTML5标签解析出错的解决办法

    解决方案 spring: thymeleaf: mode: LEGACYHTML5 <dependency> <groupId>net.sourceforge.nekohtml ...

  7. HTML5模板引擎 Thymeleaf 教程(转)

    原文:http://www.open-open.com/lib/view/open1383622135586.html Thymeleaf是一个XML/XHTML/HTML5模板引擎,可用于Web与非 ...

  8. 解决thymeleaf严格html5校验的方法

    用的是springboot加thyemleaf做静态模板. 然后会有个很烦的东西,就这个静态模板对html的格式非常严格,导致很多框架的格式都用不了,然后这里有个解除的方法: 1.在pom中添加依赖: ...

  9. sprintboot + mybaits + mysql + html5 + thymeleaf 个人笔记

    参考:https://github.com/daleiwang/moxi service @Mapper 与 @Select 等 @Mapper似乎是一个myBaits 注解,表示将java方法和sq ...

随机推荐

  1. 将jar包安装到本地Maven仓库

    1.安装jar包到本地仓库 mvn install:install-file -Dfile=F:\jiefu\lib\alipay-sdk-java20170324180803.jar -Dgroup ...

  2. oracle学习笔记(十四) 数据库对象 索引 视图 序列 同义词

    数据库对象 用户模式:指数据库用户所创建和存储数据对象的统称.在访问其它用户模式的数据库对象时需加上用户模式. 如:scott.emp, scott.dept等. 数据库对象包括:表.视图.索引.序列 ...

  3. Unity2018编辑器脚本趟坑记录

    解除预制体问题:(这个例子是解除游戏中的Canvas与Asset中的预制体的关系) if( PrefabUtility.IsAnyPrefabInstanceRoot(GameObject.Find( ...

  4. string的一些特殊点

    无论是String还是new String最终都指向了String constant pool中,只不过是String直接指向了Stringconstant pool中.而new String是在He ...

  5. CF10D LCIS 最长公共上升子序列

    题目描述 This problem differs from one which was on the online contest. The sequence a1,a2,...,an a_{1}, ...

  6. 【剑指Offer面试编程题】题目1508:把字符串转换成整数--九度OJ

    题目描述: 将一个字符串转换成一个整数,要求不能使用字符串转换整数的库函数. 输入: 输入可能包含多个测试样例. 对于每个测试案例,输入为一个合法或者非法的字符串,代表一个整数n(1<= n&l ...

  7. 【PAT甲级】1064 Complete Binary Search Tree (30 分)

    题意:输入一个正整数N(<=1000),接着输入N个非负整数(<=2000),输出完全二叉树的层次遍历. AAAAAccepted code: #define HAVE_STRUCT_TI ...

  8. Android读取权限

    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> <use ...

  9. jmeter 并发控制

    1.吞吐控制器以线程组的请求sampler为控制对象, 2.事务控制器: 3.同步定时器syn timer:对某线程组下任意的sampler任意位置作用为,有序控制单个sampler的并发先sampl ...

  10. jquery 判定checkbox是否选中

    CheckBox 判定是否选中 使用 attr('checked')来做判别是不行的,除非所有的选中取消都是使用这个属性来处理. 正确的做法是使用 .prop('checked') 来判定.