<c:forEach>终止循环

本文介绍了一种在 JSTL 的 forEach 循环中实现循环提前终止的方法,通过设置一个变量来控制循环的继续或停止,从而达到类似 break 的效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 JSTL 的 forEach 标签循环,在循环中想终止循环,但是标签里不能使用 break,那怎么样终止循环呢?且看下面的代码:

代码实例:

[html]  view plain  copy
 print ?
  1. <c:set var="loop_stop" value="0">  
  2. <c:forEach items="${list}" var="user">  
  3.     <c:if test="${loop_stop eq 0}">  
  4.         <c:if test="${user.loginName=='admin'}">  
  5.         //你需要做的判断  
  6.             <c:set var="loop_stop" value="1">  
  7.         </c:if>  
  8.     </c:if>  
  9.     <c:if test="${loop_stop eq 1}"></c:if>  
  10. </c:forEach>  
<?xml version="1.0" encoding="UTF-8"?> <definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:flowable="http://flowable.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" typeLanguage="http://www.w3.org/2001/XMLSchema" expressionLanguage="http://www.w3.org/1999/XPath" targetNamespace="http://www.flowable.org/test"> <process id="test1_1923300107290869761" name="商机立项" isExecutable="true"> <extensionElements> <flowable:executionListener event="start" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> <flowable:executionListener event="end" delegateExpression="${custFLwExecGlobalListener}"></flowable:executionListener> </extensionElements> <startEvent id="Start_1748072983902_x6bm" name="开始"></startEvent> <userTask id="Initiator_1748072985304_x6ka" name="发起人" flowable:assignee="${initiator}"> <extensionElements> <flowable:taskListener event="create" delegateExpression="${submitApplyAutoCompListener}"></flowable:taskListener> </extensionElements> </userTask> <boundaryEvent id="boundaryEvent_Approve_1748073009567_0rhm" attachedToRef="Approve_1748073009567_0rhm" cancelActivity="false"> <compensateEventDefinition></compensateEventDefinition> </boundaryEvent> <serviceTask id="multiInst_comp_Approve_1748073009567_0rhm" name="多实例补偿任务" isForCompensation="true" flowable:delegateExpression="${sequMultiInstReturnHandler}"></serviceTask> <userTask id="Approve_1748073009567_0rhm" name="部门审批" flowable:candidateGroups="1894766265457541122,1894765564253806594"> <extensionElements> <custom:apprType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[2]]></custom:apprType> <custom:emptyAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[3]]></custom:emptyAppr> <custom:isOptional xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[0]]></custom:isOptional> <custom:returnType xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[[32, 31]]]></custom:returnType> <custom:promSameAppr xmlns:custom="http://ridgeMatch.com/bpmn/extensions"><![CDATA[1]]></custom:promSameAppr> <flowable:taskListener event="create" delegateExpression="${nodeApprListener}"></flowable:taskListener> <flowable:taskListener event="complete" delegateExpression="${nodeApprListener}"></flowable:taskListener> </extensionElements> <multiInstanceLoopCharacteristics isSequential="true" flowable:collection="${candidateGroups}" flowable:elementVariable="approver"> <completionCondition>${canComplete==true && nrOfCompletedInstances>=nrOfInstances}</completionCondition> </multiInstanceLoopCharacteristics> </userTask> <endEvent id="End_1748072994507_6koo" name="流程结束"></endEvent> <sequenceFlow id="Edge_1748077535007_b60g" sourceRef="Approve_1748073009567_0rhm" targetRef="End_1748072994507_6koo"></sequenceFlow> <sequenceFlow id="Edge_1748077555219_1t0f" sourceRef="Start_1748072983902_x6bm" targetRef="Initiator_1748072985304_x6ka"></sequenceFlow> <sequenceFlow id="Edge_1751371930339_mw08" sourceRef="Initiator_1748072985304_x6ka" targetRef="Approve_1748073009567_0rhm"></sequenceFlow> <association id="assign_Approve_1748073009567_0rhm" sourceRef="Approve_1748073009567_0rhm" targetRef="multiInst_comp_Approve_1748073009567_0rhm" associationDirection="One"></association> </process> <bpmndi:BPMNDiagram id="BPMNDiagram_test1_1923300107290869761"> <bpmndi:BPMNPlane bpmnElement="test1_1923300107290869761" id="BPMNPlane_test1_1923300107290869761"></bpmndi:BPMNPlane> </bpmndi:BPMNDiagram> </definitions>
最新发布
08-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值