原文链接:

http://somefuture.iteye.com/blog/2253761

Thymeleaf是另一个Java视图模板引擎,使用上和FreeMarker各有千秋,不了解的可以从其他博文里学习一下。我这里主要记录一下它的内置属性。

本文不是Thymeleaf入门教程,也不是对其标签进行全面讲解只对其属性等价标签进行记录,以为辞典。

Thymeleaf提供了一个标签th:attr,可以把多个DOM标签用逗号分隔后写进去:

  1. <img src="../../images/gtvglogo.png"
  2. th:attr="src=@{/images/gtvglogo.png},title=#{logo},alt=#{logo}" />

这个例子里给<img>标签设置了三个属性标签:src、title、alt。<img>自带的src会被Thymeleaf处理后扔掉而使用自己的。

这个标签不太优雅,不仅写起来紊乱,读起来也凌乱。所以很少用,一般用其他的代替:

  1. <img src="../../images/gtvglogo.png"
  2. th:src="@{/images/gtvglogo.png}" th:title="#{logo}" th:alt="#{logo}" />

作为th:attr的实例用法,Thymeleaf提供了几乎全部标签的Thymeleaf等价标签:

th:abbr th:accept th:accept-charset
th:accesskey th:action th:align
th:alt th:archive th:audio
th:autocomplete th:axis th:background
th:bgcolor th:border th:cellpadding
th:cellspacing th:challenge th:charset
th:cite th:class th:classid
th:codebase th:codetype th:cols
th:colspan th:compact th:content
th:contenteditable th:contextmenu th:data
th:datetime th:dir th:draggable
th:dropzone th:enctype th:for
th:form th:formaction th:formenctype
th:formmethod th:formtarget th:frame
th:frameborder th:headers th:height
th:high th:href th:hreflang
th:hspace th:http-equiv th:icon
th:id th:keytype th:kind
th:label th:lang th:list
th:longdesc th:low th:manifest
th:marginheight th:marginwidth th:max
th:maxlength th:media th:method
th:min th:name th:optimum
th:pattern th:placeholder th:poster
th:preload th:radiogroup th:rel
th:rev th:rows th:rowspan
th:rules th:sandbox th:scheme
th:scope th:scrolling th:size
th:sizes th:span th:spellcheck
th:src th:srclang th:standby
th:start th:step th:style
th:summary th:tabindex th:target
th:title th:type th:usemap
th:value th:valuetype th:vspace
th:width th:wrap th:xmlbase
th:xmllang th:xmlspace  

比如:

  1. <form action="subscribe.html" th:action="@{/subscribe}">
  2. <a href="product/list.html" th:href="@{/product/list}">Product List</a>

这里使用了th:action和th:href标签。

Thymeleaf还提供了两个合成标签:

th:alt-title th:lang-xmllang

用于同时设置两个属性,比如;

  1. <img src="../../images/gtvglogo.png"
  2. th:src="@{/images/gtvglogo.png}" <strong>th:alt-title</strong>="#{logo}" />

还有两个CSS标签:

 th:classappend  th:styleappend

意思显而易见,用法如下:

  1. <tr th:each="prod : ${prods}" class="row" th:classappend="${prodStat.odd}? 'odd'">

对于判断性的标签,比如checked

  1. <input type="checkbox" name="option1" checked="checked" />

只能使用checked作为其值,即使使用true都不好使。Thymeleaf提供了这些标签的等价标签,值可以是判断语句,不为真会删除该标签:

th:async th:autofocus th:autoplay
th:checked th:controls th:declare
th:default th:defer th:disabled
th:formnovalidate th:hidden th:ismap
th:loop th:multiple th:novalidate
th:nowrap th:open th:pubdate
th:readonly th:required th:reversed
th:scoped th:seamless th:selected

比如:

  1. <input type="checkbox" name="active" th:checked="${user.active}" />

Thymeleaf的内置属性(转)的更多相关文章

  1. Thymeleaf 之 内置对象、定义变量、URL参数及标签自定义属性

    Thymeleaf 之 内置对象.定义变量.URL参数及标签自定义属性 本文章来自[知识林] 如标题所述,这篇文章主要讲述Thymeleaf中的内置对象(list解析.日期格式化.数字格式化等).定义 ...

  2. javascript内置属性——arguments

    arguments是javascript中的内置属性,可以直接调用函数的参数,作用类似Array,但本身并不是数组.这次发现它是为了实现封装函数,将不确定数量的数字乘积.比如function mult ...

  3. Ant 脚本打印系统属性变量、ant内置属性

    Ant 脚本打印系统属性变量.ant内置属性 作用 编写ant脚本的时候,经常会引用到系统属性,本脚本用于打印系统常用属性(System.getProperties)与环境变量(Environment ...

  4. JavaScript学习——内置属性

    在js中,几乎所有的对象都是同源对象,都继承Object对象.对象的内置属性指的是它们作为Object实例所具有的属性,这些属性通常反映对象本身的基本信息和数据无关.因此我们称它们为元属性.这些属性通 ...

  5. 对象的内置属性和js的对象之父Object()

    js中对象有constructor,valueOf(),toString()等内置属性和方法; 创建一个空对象的方法: var o = {}; 或者 var o= new Object(); o.co ...

  6. Maven内置属性

    1.内置属性:如${project.basedir}表示项目根目录,${ project.version}表示项目版本 2.POM属性:用户可以引用pom文件中对应的值.如: ${project.bu ...

  7. Maven内置属性、POM属性

    1.内置属性(Maven预定义,用户可以直接使用) ${basedir}表示项目根目录,即包含pom.xml文件的目录; ${version}表示项目版本; ${project.basedir}同${ ...

  8. python的反射函数(hasattr()、getattr()、setattr()与delattr())和类的内置属性attr(__getattr()__、__setattr()__与__delattr()__)

    主要是指程序可以访问.检测和修改它本身状态或行为的一种能力(自省),有四个可以实现自省函数. hasattr(object,name) 判断object中是否有name字符串对应的属性或方法,返回Tr ...

  9. Maven内置属性,pom属性

    内置属性(Maven预定义,用户可以直接使用) ${basedir}表示项目根目录,即包含pom.xml文件的目录; ${version}表示项目版本; ${project.basedir}同${ba ...

随机推荐

  1. Linux新建SVN版本库

    1.进入svn 版本库(如/www/svn) 2.创建svn 版本库svnadmin create  edition 3.进入新建的版本库库目录cd edition 4.进入版本库配置目录cd con ...

  2. js递归生成树形下拉菜单

    需求:我需要把一个单表的数据转换成类似菜单那种如图所示:我呢需要把这个菜单树放入到下框里面去如图所示: 下面是实现思路:1.第一步1.1var afTypeJson=${afTypeJson}// 这 ...

  3. 吴裕雄 python 机器学习——模型选择参数优化随机搜索寻优RandomizedSearchCV模型

    import scipy from sklearn.datasets import load_digits from sklearn.metrics import classification_rep ...

  4. Typora自动生成标题编号

    1.要实现的效果 按照markdown语法输入  # 一级标题后,自动生成前面的编号 2.配置方法 2.1.进入目录 2.2.创建文件 2.3.编辑文件 base.user.css /** initi ...

  5. windows maven配置

    <?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...

  6. 大数据计算引擎之Flink Flink CEP复杂事件编程

    原文地址: 大数据计算引擎之Flink Flink CEP复杂事件编程 复杂事件编程(CEP)是一种基于流处理的技术,将系统数据看作不同类型的事件,通过分析事件之间的关系,建立不同的时事件系序列库,并 ...

  7. spark实验(二)--scala实验(3)

    实验1,计算级数: 首先打开安装完scala ide的eclipse,在eclipse 中新建一个scala project. 然后新建一个scala的object对象 导入scala.io.StdI ...

  8. java月利率计算(等额本息贷款)

    等额本息 每月还款计算公式: 每月本息金额 = (本金×月利率×(1+月利率)^还款月数)÷ ((1+月利率)^还款月数-1)) 反转求出 月利率 月利率 如果根据上面公式反转是算不出来的. 下面给出 ...

  9. day46_Webservice学习笔记_02

    一.回顾昨天所学 什么是webservice?    什么是远程调用技术?答:系统和系统之间的调用,从远程系统当中获取业务数据.    Webservice是web服务,他是用http传输SOAP协议 ...

  10. 以太坊执行miner.start返回null终极解决方案

    参考博文:https://blog.csdn.net/wo541075754/article/details/79260040