freemarker循环遍历及只显示前几个元素以及处理第一个和最后一个元素
作者:互联网
freemarker循环遍历及只显示前几个元素
<#list beans as bean>
<#if (bean_index <= 4)>
<span>${bean.label}:</span><input name="${bean.col}" style="line-height:26px;border:1px solid #ccc">
</#if>
</#list>
1、取前几条数据
<@_categoryList id=4 >
<#assign n = 0 /> // list外先定义assign
<#list page.list as column>
<#assign n = n+1 /> // list里面再定义assign
<#if n gt 3><#break></#if> // 取前三条数据
<div>
<h4>${(column.name)!}</h4>
</div>
</#list>
</@_categoryList>
2、取某一条数据
<#list page.list as column>
<#if column_index == 0> // 直接取下标
<div>
<h4>${(column.name)!}</h4>
</div>
</#if>
</#list>
<#list depts as entity>
<#if entity_index = 0>第一个
'[{"id":${entity.deptId},"pid":0,"status":1,"name":"${entity.deptName}"},'+
</#if >
'{"id":${entity.deptId},"pid":0,"status":1,"name":"${entity.deptName}"},' +
</#list>
<#list positions as entity>
<#if entity_has_next>
'{"id":${entity.id},"pid":${entity.deptid},"status":1,"name":"${entity.name}"},' +
<#else >最后一个
'{"id":${entity.id},"pid":${entity.deptid},"status":1,"name":"${entity.name}"}]');
</#if>
</#list>
————————————————
版权声明:本文为CSDN博主「abckingaa」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/abckingaa/article/details/117929876
标签:status,遍历,name,freemarker,元素,pid,entity,id 来源: https://www.cnblogs.com/webSnow/p/16598350.html