freemarker循环、下标及判断
一、freemarker中list循环使用非常频繁,下面介绍lfreemarker中list简单的用法
1、在freemarker中遍历list数组使用list指令:<#list sequence as item>...</#list>;
其中sequence为集合(controller)的表达式,item是循环变量名(别名),不可是表达式;
在遍历sequence的时候会将sequence中的变量或者对象放到item中,后面使用时只需用item即可;
例如:<#list libraryVOs as libraryVO>
注: libraryVOs集合为标签集合,GroupDTO为标签组
libraryVOs为sequence表达式,libraryVO为item变量;libraryVOS中有多个GroupDTO对象,在遍历时会将GroupDTO存放到libraryVO中。如果取GroupDTO中的名称
使用${libraryVO.applyName};
2、item_index:当前迭代项在所有迭代项中的位置,是数字值。
3、freemarker判断<#if (x>y)></#if> 注:要使用括号括起来
<ul> <#list libraryVOs as libraryVO> <li> <span class="content-l-title">${libraryVO.groupDto.applyName}(${libraryVO.count}):</span> <ul class="content-l-content"> <#list libraryVO.labelDto as labelLibrary> <#if (labelLibrary_index <= 3)> <li> <span class="second-title">${labelLibrary.applyName}:</span> <span class='second-title hide' id='labelId${labelLibrary.autoId}'>${labelLibrary.applyName}</span> <label for="checkbox10" class="checkbox${labelLibrary.autoId}0" onclick="getLabelCustom(${labelLibrary.autoId})"> <input type="radio" id="checkbox0${labelLibrary.autoId}" value="1" name="tag1"> <b><img src="${resRoot}/css/images/xianze.png" alt=""></b> 自定义 </label> <label for="checkbox11" class="checkbox${labelLibrary.autoId}1" onclick="getLabelAll(${labelLibrary.autoId})"> <input type="radio" id="checkbox1${labelLibrary.autoId}" value="0" name="tag1"> <b><img src="${resRoot}/css/images/xianze.png" alt=""></b> 不限 </label> <input id="tagSel${labelLibrary.autoId}" name="tagSel${labelLibrary.autoId}" onclick="showTag(${labelLibrary.autoId}); return false;" class="tag-item ${labelLibrary.autoId} hide" type="text" readonly value=""> <input id="tagSelId${labelLibrary.autoId}" name="tagSelId${labelLibrary.autoId}" type="hidden" value="" style="width:120px;"> <div id="tagContent${labelLibrary.autoId}" class="tagContent${labelLibrary.autoId}" style="position: absolute; left: 64px; display:none;width:160px;height:200px;overflow-y:scroll;overflow-x:auto;z-index:5555;background: #fff;"> <ul id="tagDemo${labelLibrary.autoId}" class="ztree"></ul> </div> </li> </#if> <#if (labelLibrary_index > 3)> <li class="list hide"> <span class="second-title">${labelLibrary.applyName}:</span> <span class='second-title hide' id='labelId${labelLibrary.autoId}'>${labelLibrary.applyName}</span> <label for="checkbox10" class="checkbox${labelLibrary.autoId}0" onclick="getLabelCustom(${labelLibrary.autoId})"> <input type="radio" id="checkbox0${labelLibrary.autoId}" value="1" name="tag1"> <b><img src="${resRoot}/css/images/xianze.png" alt=""></b> 自定义 </label> <label for="checkbox11" class="checkbox${labelLibrary.autoId}1" onclick="getLabelAll(${labelLibrary.autoId})"> <input type="radio" id="checkbox1${labelLibrary.autoId}" value="0" name="tag1"> <b><img src="${resRoot}/css/images/xianze.png" alt=""></b> 不限 </label> <input id="tagSel${labelLibrary.autoId}" name="tagSel${labelLibrary.autoId}" onclick="showTag(${labelLibrary.autoId}); return false;" class="tag-item ${labelLibrary.autoId} hide" type="text" readonly value=""> <input id="tagSelId${labelLibrary.autoId}" name="tagSelId" type="hidden" value="" style="width:120px;"> <div id="tagContent${labelLibrary.autoId}" class="tagContent${labelLibrary.autoId}" style="position: absolute; left: 64px; display:none;width:160px;height:200px;overflow-y:scroll;overflow-x:auto;z-index:5555;background: #fff;"> <ul id="tagDemo${labelLibrary.autoId}" class="ztree"></ul> </div> </li> </#if> </#list> <#if (libraryVO.labelDto?size > 3)> <li> <span class="l-more">更多<i class="more-icon"></i></span> <span class="l-close hide">收起<i class="close-icon"></i></span> </li> </#if> </ul> </li> </#list> </ul>