原文链接:

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. queue 官方运用

    import threading import random,time import queue q_init = queue.Queue(maxsize=5) import logging logg ...

  2. 日期格式在ios中的兼容性

    在IOS中支持 2017/3/2 这种格式的日期 不支持2017-3-2日期 /** * 返回兼容ios.android的日期时间格式 * @param dateTime String * @retu ...

  3. django之关系及查询,数据类型,约束,分页

    目录 关系 数据列类型 数据类型的约束 分页 关系 1. 一对一(水平分表) 母表: UserInfo id name age 子表: private id salary sp 创建模型语句: cla ...

  4. Visual Studio调试Tersseract

    在Visual Studio中打开Tesseract项目,然后项目-->属性-->调试-->命令变量: 比如在debug目录下有一张 test.jpg的图片,里面有中文需要识别,命令 ...

  5. 判断是app 或者 网页

    function openInWebview () { let ua = navigator.userAgent.toLowerCase(); if (ua.match(/MicroMessenger ...

  6. Java面向对象内存图

    1. java虚拟机的内存划分 2. 苹果手机类 package cn.itcast.day06.demo02; /* 定义一个类,用来模拟“手机”事物. 属性:品牌.价格.颜色 行为:打电话.发短信 ...

  7. 拥抱高通的联想,真的能靠5G突围?

    编辑 | 于斌 出品 | 于见(mpyujian) 2016年,对于常年自我标榜为"民族企业"的联想来说是品牌口碑的"转折之年".它在这一年的5G信道编码标准方 ...

  8. Centos7 安装virtualenv bash: virtualenv: command not found...的解决

    安装好了python3的环境前提下 1.使用pip3安装virtualenv pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple virt ...

  9. Java连载81-枚举类型,生成五个不重复的随机数,集合简介

    一.枚举类型 1.枚举类型的格式就是enum+枚举类型的名称,可见下面的例子. package com.bjpowernode.java_learning; ​ public class D81_1_ ...

  10. 通过命令创建Django项目

    本人是使用window10操作系统进行讲解Django框架,Linux系统和windows版本几乎一致,可以自行学习就可以解决. 首先在系统上创建了虚拟环境,如果不会创建,可以根据这篇文章学习:htt ...