Thymeleaf的内置属性
2015-11-17 17:52
337 查看
Thymeleaf是另一个Java视图模板引擎,使用上和FreeMarker各有千秋,不了解的可以从其他博文里学习一下。我这里主要记录一下它的内置属性。
本文不是Thymeleaf入门教程,也不是对其标签进行全面讲解只对其属性等价标签进行记录,以为辞典。
Thymeleaf提供了一个标签th:attr,可以把多个DOM标签用逗号分隔后写进去:
Html代码
<img src="../../images/gtvglogo.png"
th:attr="src=@{/images/gtvglogo.png},title=#{logo},alt=#{logo}" />
这个例子里给<img>标签设置了三个属性标签:src、title、alt。<img>自带的src会被Thymeleaf处理后扔掉而使用自己的。
这个标签不太优雅,不仅写起来紊乱,读起来也凌乱。所以很少用,一般用其他的代替:
伦理片 http://www.dotdy.com/
Html代码 <img src="../../images/gtvglogo.png"
th:src="@{/images/gtvglogo.png}" th:title="#{logo}" th:alt="#{logo}" />
作为th:attr的实例用法,Thymeleaf提供了几乎全部标签的Thymeleaf等价标签:
|
Html代码
<form action="subscribe.html" th:action="@{/subscribe}">
<a href="product/list.html" th:href="@{/product/list}">Product List</a>
这里使用了th:action和th:href标签。
Thymeleaf还提供了两个合成标签:
th:alt-title | th:lang-xmllang |
Html代码
<img src="../../images/gtvglogo.png"
th:src="@{/images/gtvglogo.png}" <strong>th:alt-title</strong>="#{logo}" />
还有两个CSS标签:
th:classappend | th:styleappend |
Html代码
<tr th:each="prod : ${prods}" class="row" th:classappend="${prodStat.odd}? 'odd'">
影音先锋电影 http://www.iskdy.com/
对于判断性的标签,比如checked
Html代码
<input type="checkbox" name="option1" checked="checked" />
只能使用checked作为其值,即使使用true都不好使。Thymeleaf提供了这些标签的等价标签,值可以是判断语句,不为真会删除该标签:
|
Html代码
<input type="checkbox" name="active" th:checked="${user.active}" />
相关文章推荐
- 实习整理(九)
- CoordinatorLayout与滚动的处理
- 今天发现一个新的学习网址
- 技术学习的一些感慨-人之为学
- Kafka深度解析
- 3D感应手机Project Tango 拆机 ,实时三维场景重建
- 技术学习的一些感慨-人之为学
- 技术学习的一些感慨-人之为学
- javascript高级程序设计(二)navigator.plugin浏览器插件检测
- C# Winform 跨线程更新UI控件常用方法汇总
- Jquery easy ui dataGrid
- Delphi中的异常处理(10种异常来源、处理、精确处理)
- 2015-112 ado.net2
- Nexus 部署Maven私服仓库
- CentOS7 初次安装记录(三)配置PHP和MYSQL
- 芒果iOS开发之Xcode安装Empty Application
- oc构造函数和@property属性
- jquery中attr和prop的区别
- shrio学习
- 尝试一下