0

JSTL の拡張 for ループでブレークを使用する方法。私のコード MyModelObjectを確認してください

@RequestMapping(value="/g/{domainId}/{userId}/{userName}/fullProfile.htm" ,method=RequestMethod.GET)
public String showFullProfile(@PathVariable("domainId")Long domainId,@PathVariable("userName")String userName,@PathVariable("userId")Long userId,Model model) throws Exception {
     try {
                   List<Domains> domains = bal.getDomains();
                      model.put("domain",domains);
                }
                catch(Exception e)
              {
           }
return test;
}

test.jsp

              <c:forEach items="${domain}" var="domain">
                 ${domain.departmentName}

                </c:forEach>

私の問題は毎回 6 レコードしかフェッチしないことですが、for ループが 6 番目のレコードに達したときに for ループを停止したいのですが、どうすればこれを行うことができますか?

4

2 に答える 2

0

forEach の varStatus 属性を使用します。

<c:forEach items="${domain}" var="domain" varStatus="status">
   <c:if test="${status.count le 6}">
      ${domain.departmentName}
   </c:if>
</c:forEach>
于 2013-09-25T09:28:30.047 に答える
0

これが1つの解決策です。試してないので試してみてください。

<c:set var="count" value="0" scope="page" />
<c:forEach items="${domain}" var="domain">
  <c:if test="${count < 6}">
    ${domain.departmentName}
    <c:set var="count" value="${count + 1}" scope="page" />
  </c:if>
</c:forEach>
于 2013-09-20T06:39:27.953 に答える