thymeleaf常用標(biāo)簽
1. th:checked ,th:selected標(biāo)簽
<input type="radio" value="M" name="gender" th:checked="${data.gender}=='M'"/>男
<input type="radio" value="F" name="gender" th:checked="${data.gender}=='F'"/>女
<option th:selected="${cookie[draftStatus]}?${cookie[draftStatus].getValue()}=='WSH':false">未審核</option>
2. 日期格式化,字符串截取
<span th:text="${#calendars.format(customerInfoVO.gmtCreated,'yyyy-MM-dd HH mm')}"></span>
<span th:text="${#strings.substring(entity.contactTime,0,10)}"></span>
tempo 寫(xiě)法 <span>{{gmtCreate | date 'YYYY-MM-DD HH:mm'}} </span>
3. a 標(biāo)簽帶參數(shù)
<a th:if="(${entity.draftStatus}=='審核不通過(guò)') or (${entity.draftStatus}=='已發(fā)布') " class="btn btn-info" th:href="@{getItemById?(id=${entity.id},draftStatus=${entity.draftStatus}) }">編輯</a>
th:href="@{/index/bannerList}" 加‘/’ url 取相對(duì)路徑 (http://localhost:8081/bauna)
4.th:attr
th:attr="itemId='DQR'+${entity.id},'src'=${entity.itemImg}"
5.列表序號(hào) 從1開(kāi)始
<th:block th:each="entity,itemStat : ${contactNotes.getContactNotes()}">
<tr class="alignCenter entryOrderRow">
<td th:text="${itemStat.count+((page.curPage-1)*page.pageSize)}"></td>
<td th:text="${#calendars.format(entity.gmtCreate,'yyyy-MM-dd')}"></td>
</tr>
</th:block>
6.判斷條件 表達(dá)式
<span th:if="1==1"></span> thymeleaf
{% if changeAmountTimes == 0 %} tempo模板
1111
{% else %}
22222
{% endif %}
7. 三元表達(dá)式
<td th:text="${entity.contactTimeNext!=null?(#strings.substring(entity.contactTimeNext,0,10)):' '}"></td>
8.tempo 渲染
<tr data-template-for="userRoleOrgList">
<td colspan="2">部門(mén):<span>{{orgName}}</span></td>
<td colspan="10">角色:<span>{{roleDescription}}</span></td>
</tr>
userRoleOrgList為user 對(duì)象屬性時(shí) 循環(huán)userRoleOrgList
9.字符串處理
${#strings.length(entity.content)} 獲取字符串長(zhǎng)度
${#strings.substring(entity.content,0,20)} 截取
10.頁(yè)面數(shù)據(jù)供js 調(diào)用
<script th:inline="javascript">
/*<![CDATA[*/
var goodsList = [[${goodsList}]];
/*]]>*/
</script>
11.th:class, th:classappend, th:colspan
<tr th:classappend="(${entity.isContact}=='Y')?a:b" class="row-body alignCenter">
如果${entity.isContact}=='Y' tr 采用樣式a , 否則 用樣式 b
<td th:colspan="${orderEntity.invoiceStatus}!=null?2:3"></td>
12.轉(zhuǎn)義標(biāo)簽 th:utext
<span style="color:#41a1d2;" >2016-06-17 16:43</span>
tempo 轉(zhuǎn)義 :Tempo.prepare('orderTempo',{'escape': false})
13.工具類(lèi)
日期處理 ${#dates.format(date,'dd/MMM/yyyy HH:mm')}
${#calendars.format(cal,'dd/MMM/yyyy HH:mm')}
數(shù)字 ${#numbers.formatInteger(1000000,3,'COMMA')}
字符串 ${#strings.contains(name,'EZ')}
$(#strings.substring(name,3,5))
集合 ${#arrays.length(array)}
${#lists.size(list)}
posted on 2016-07-30 17:32 youyou365 閱讀(1120) 評(píng)論(0) 收藏 舉報(bào)
浙公網(wǎng)安備 33010602011771號(hào)