thymeleaf常用的一些标签属性

thymeleaf模版,总结了下经常用到的一些属性:
从后台传过来一个List,需要到前端页面显示,所以一般先进行判断——该List是否为空,然后才是加载内容,而有些页面加载的时候需要获取序号,具体代码如下:

<th:block th:if="${not #lists.isEmpty(purchaseDemandList)}">
    <li class="list-group-item row entry-default-child entry-default-xs weaker-font-color text-center">
        <div><span>序号</span></div>
        <div><span>名称</span></div>
        <div><span>周期</span></div>
        <div><span>数量</span></div>
    </li>
    <th:block th:each="purchaseDemand,index:${purchaseDemandList}">
        <li class="list-group-item row entry-default-child entry-default-xs weaker-font-color text-center">
            <div><span th:text="${index.count}">序号</span></div>
            <div><span th:text="${purchaseDemand.goodsName}" >商品名称</span></div>
            <div><span th:if="${purchaseDemand.purchaseCycle=='half_month'?'半个月':'一个月'}">采购周期</span></div>
            <div><span th:text="${purchaseDemand.num}"> 数量</span></div>
        </li>
    </th:block>
</th:block>

序号对象获取:

<th:block th:each="purchaseDemand,index:${purchaseDemandList}">
<span th:text="${index}">序号</span>
</th:block>

${index}结果如下:
1
时间格式化

 th:text="${#calendars.format(nowTime,'yyyy-MM-dd')}"

原文地址:http://blog.csdn.net/zheng911209/article/details/48181285

猜你喜欢

转载自blog.csdn.net/hhdhz/article/details/87967961