thymeleaf 个人常用标签

th:text=”${}”//取文本值

th:href=”${}”//链接值

th:style=”${}”//css样式值

th:each迭代循环

iterStat称作状态变量,属性有:
    index:当前迭代对象的index(从0开始计算)
    count: 当前迭代对象的index(从1开始计算)
    size:被迭代对象的大小
    current:当前迭代变量
    even/odd:布尔值,当前循环是否是偶数/奇数(从0开始计算)
    first:布尔值,当前循环是否是第一个
    last:布尔值,当前循环是否是最后一个
引用自:[点击链接跳转](http://blog.csdn.net/sun_jy2011/article/details/40710429)
<ol>  
        <li>List循环:  
            <table border="1">  
              <tr>  
                <th>用户名</th>  
                <th>邮箱</th>  
                <th>管理员</th>  
                <th>状态变量:index</th>  
                <th>状态变量:count</th>  
                <th>状态变量:size</th>  
                <th>状态变量:current.userName</th>  
                <th>状态变量:even</th>  
                <th>状态变量:odd</th>  
                <th>状态变量:first</th>  
                <th>状态变量:last</th>  
              </tr>  
              <tr  th:each="user,userStat : ${list}">  
                <td th:text="${user.userName}">Onions</td>  
                <td th:text="${user.email}">test@test.com.cn</td>  
                <td th:text="${user.isAdmin}">yes</td>  
                 <th th:text="${userStat.index}">状态变量:index</th>  
                <th th:text="${userStat.count}">状态变量:count</th>  
                <th th:text="${userStat.size}">状态变量:size</th>  
                <th th:text="${userStat.current.userName}">状态变量:current</th>  
                <th th:text="${userStat.even}">状态变量:even****</th>  
                <th th:text="${userStat.odd}">状态变量:odd</th>  
                <th th:text="${userStat.first}">状态变量:first</th>  
                <th th:text="${userStat.last}">状态变量:last</th>  
              </tr>  
            </table>  
        </li>  
        <li>Map循环:  
            <div th:each="mapS:${map}">  
            <div th:text="${mapS}"></div>  
            </div>  
        </li>  
        <li>数组循环:  
            <div th:each="arrayS:${arrays}">  
            <div th:text="${arrayS}"></div>  
            </div>  
        </li>  
        </ol>  

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

第一种:
<img src="../../images/gtvglogo.png"  
th:attr="src=@{/images/gtvglogo.png},title=#{logo},alt=#{logo}" /> 
第二种:
<img src="../../images/gtvglogo.png"  
th:src="@{/images/gtvglogo.png}" th:title="#{logo}" th:alt="#{logo}" />   

attr写法

th:abbrth:acceptth:accept-charset
th:accesskeyth:actionth:align
th:altth:archiveth:audio
th:autocompleteth:axisth:background
th:bgcolorth:borderth:cellpadding
th:cellspacingth:challengeth:charset
th:citeth:class th:classid
th:codebaseth:codetypeth:cols
th:colspanth:compact th:content
th:contenteditableth:contextmenuth:data
th:datetimeth:dirth:draggable
th:dropzoneth:enctypeth:for
th:formth:formactionth:formenctype
th:formmethodth:formtargetth:frame
th:frameborderth:headersth:height
th:highth:hrefth:hreflang
th:hspaceth:http-equivth:icon
th:idth:keytypeth:kind
th:labelth:langth:list
th:longdescth:lowth:manifest
th:marginheightth:marginwidthth:max
th:maxlengthth:mediath:method
th:minth:nameth:optimum
th:patternth:placeholderth:poster
th:preloadth:radiogroupth:rel
th:revth:rowsth:rowspan
th:rulesth:sandboxth:scheme
th:scopeth:scrollingth:size
th:sizesth:spanth:spellcheck
th:srcth:srclangth:standby
th:startth:stepth:style
th:summaryth:tabindexth:target
th:titleth:typeth:usemap
th:valueth:valuetypeth:vspace
th:widthth:wrapth:xmlbase
th:xmllangth:xmlspace
<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

同时这是两个标签比如:

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

还有两个css标签

th:classappend   th:styleappend

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

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

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

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

th:asyncth:autofocusth:autoplay
th:checkedth:controlsth:declare
th:defaultth:deferth:disabled
th:formnovalidateth:hiddenth:ismap
th:loopth:multipleth:novalidate
th:nowrapth:openth:pubdate
th:readonlyth:requiredth:reversed
th:scopedth:seamlessth:selected

比如:

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

参考文章:http://somefuture.iteye.com/blog/2253761

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值