使用多个数据对象创建具有复杂条件的规则

时间:2017-11-22 08:37:13

标签: drools rule-engine

假设我有两个数据对象PersonAddress。 Person对象包含字段namegender,Address对象包含字段citystate。现在我想根据这个条件采取一些行动:

when
    (person.name == 'jayram' && address.city == 'barhiya') || 
    (person.gender == 'M' && address.state == 'bihar')
then
    do something

如何在drools规则文件中完成此操作?

1 个答案:

答案 0 :(得分:0)

也许这应该是解决方案:

package com.sample

dialect "mvel"

import com.sample.Person;
import com.sample.Address;

rule "Hello World"
    when
        person : Person( status == Message.HELLO)
        Address((person.name == 'jayram' && city == 'barhiya') ||
 (person.gender == 'M' && state == 'bihar'))
    then
        // Do something
end