如何打印出匹配 c:if 语句的次数

how to print out how much times it is match the c:if statement

我的代码如下所示:

<table border 1>
    <tr>
        <th>Toteutus tunnus</th>
        <th>Toteutus nimi</th>
        <th>Toteutus opettaja</th>
        <th>Palautteen määrä</th>
    </tr>
<c:forEach items="${toteutukset}" var="toteutus">
    <tr>
        <td><a href="/palaute/main/toteutuksenpalautteet/${toteutus.toteutusID}">${toteutus.toteutusTunnus}</a></td>
        <td>${toteutus.toteutusNimi}</td>
        <td>${toteutus.opettajaNimi}</td>
        <td>
<c:forEach items="${palautteet}" var="palaute" varStatus="count">
<c:if test="${toteutus.toteutusID == palaute.toteutusID }">

</c:if>
</c:forEach>
        </td>
    </tr>


</c:forEach>
</table>

首先,我打印出课程列表 (toteutus) 中的所有内容,然后检查反馈列表 (palautteet),然后我使用 c:if 查看每门课程有多少反馈,我想显示每门课程旁边的反馈数量,但我不知道如何。请帮助

第一个建议是在您的后端代码中执行此操作,方法是将其添加到对象 toteutus。无论如何,如果你想保留你的代码,你可以这样做:

    <td>
       <c:set var="nrOfFeedbacks" value="0" scope="page"/>
       <c:forEach items="${palautteet}" var="palaute" varStatus="count">
         <c:if test="${toteutus.toteutusID == palaute.toteutusID }">
            <c:set var="nrOfFeedbacks" value="${nrOfFeedbacks+ 1}" scope="page"/>
         </c:if>
      </c:forEach>
      //set html for counter
      ${nrOfFeedbacks}
   </td>