我可以在struts 1的逻辑迭代中循环吗?

时间:2013-05-18 05:19:13

标签: java jsp struts

考虑像这样的db返回

roll-no:10csu001 student_name:aravind presentabsent:p,p,p,p date:10/4/2013 
roll-no:10csu001 student_name:aravind presentabsent:p,p,p,p date:11/4/2013
roll-no:10csu002 student_name:azhar   presentabsent:p,p,a,p date:10/4/2013 
roll-no:10csu002 student_name:azhar   presentabsent:p,p,a,p date:11/4/2013 

<logic:iterate id="vStudentList" name="reqStudentAttendanceList" 
          type="form.StudentForm" scope="request" indexId="i" >
    <td>
        <span>
            <bean:write name="vStudentList" property="roll_no"/>
        </span>
    </td>
    <td>
        <span>
            <bean:write name="vStudentList" property="student_name"/>
        </span>
    </td>
    <td>
        <span>
            <bean:write name="vStudentList" property="presentabsent"/>
        </span>
    </td> 

这也让我有这样的o / p

10csu001 aravind p,p,p,p 10/4/2013 
10csu001 aravind p,p,p,p 11/4/2013 

对于每个日期,所以我想像这样打印

10csu001 aravind p,p,p,p 10/4/2013 
                 p,p,p,p 11/4/2013  

我怎么能迭代呢?

1 个答案:

答案 0 :(得分:1)

尝试使用<c:if>检查当前行是否打印出与之前一行相同的学生的数据。您也可以使用<c:otherwise>来实现else阻止,并在<span>中打印其他内容。

<logic:iterate id="vStudentList" name="reqStudentAttendanceList" 
          type="form.StudentForm" scope="request" indexId="i" >
    <td>
        <span>
            <c:if test="${i > 1 && reqStudentAttendanceList[i-1].roll_no != reqStudentAttendanceList[i-2].roll_no}">
                <bean:write name="vStudentList" property="roll_no"/>
            </c:if>
        </span>
    </td>
    <td>
        <span>
            <c:if test="${i > 1 && reqStudentAttendanceList[i-1].student_name != reqStudentAttendanceList[i-2].student_name}">
                <bean:write name="vStudentList" property="student_name"/>
            </c:if>
        </span>
    </td>
    <td>
        <span>
            <bean:write name="vStudentList" property="presentabsent"/>
        </span>
    </td>    <td>
        <span>
            <bean:write name="vStudentList" property="date"/>
        </span>
    </td>
</logic:iterate>