【问题标题】:How to do null or empty check in drools - mvel dialect?如何在 drools - mvel 方言中进行 null 或空检查?
【发布时间】:2018-07-16 11:10:42
【问题描述】:

当 configList 为 null 时,AND 逻辑不应继续进行,但我收到此错误 - “数组索引超出范围”

以下是规则:

rule "testRule"
   when
       config : Config( configList != null && !configList.empty && configList[0].attribute != null )
   then
       // logic
end

【问题讨论】:

  • 在回答您的问题之前,您是否知道检查 null 与检查“emptiness”不同?
  • 您好,我知道区别,但我发布了错误的代码,请检查编辑后的代码,因为它仍然给出相同的错误。

标签: drools rules business-rules mvel


【解决方案1】:

由于 Drools 执行规则条件的方式,不能保证短路逻辑运算符。在某些情况下,它们可以工作,但在其他情况下,它们不会。

作为一种解决方法,您可以将拥有的单个模式分成两部分:

rule "testRule"
when
  config : Config( $configList: configList != null, configList.empty == false)
  Attribute() from $configList.get(0)
then
  // logic
end

我假设$configListAttribute 对象的列表。

希望对你有帮助,

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-11-30
    • 2014-08-14
    • 1970-01-01
    • 2014-07-26
    • 2012-09-15
    • 1970-01-01
    • 2012-01-18
    相关资源
    最近更新 更多