首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在Drools,Mvel方言中打破循环?

如何在Drools,Mvel方言中打破循环?
EN

Stack Overflow用户
提问于 2018-08-06 22:25:44
回答 1查看 612关注 0票数 0

在下面的规则中,then-part中的逻辑是为所有通过给定条件的子对象执行的,我想在then-part中的逻辑只执行一次后中断循环,如何做到这一点

代码语言:javascript
复制
rule "test"
            when
                Parent( $childList : childList != null, childList.empty == false)
                Child('testing'.equalsIgnoreCase(attribute)) from $childList
            then
                // testLogic
end
EN

回答 1

Stack Overflow用户

发布于 2018-08-06 22:42:33

如果不需要在RHS中引用Child对象(或其任何属性),则可以使用exists运算符:

代码语言:javascript
复制
rule "test"
when
 Parent( $childList : childList != null, childList.empty == false)
 exists Child('testing'.equalsIgnoreCase(attribute)) from $childList
then
 // testLogic
end

如果出于某种原因,您确实需要Child对象或它的任何属性,您可以这样做(尽管这不是很好):

代码语言:javascript
复制
rule "test"
when
 Parent( $childList : childList != null, childList.empty == false)
 $c: Child('testing'.equalsIgnoreCase(attribute)) from $childList.get(0)
then
 // testLogic
end

希望能有所帮助,

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51709893

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档