问题
Assume that I have two data objects Person
and Address
. Person object has the fields name
and gender
and Address object has the fields city
and state
. Now I want to take some action based on this condition :
when
(person.name == 'jayram' && address.city == 'barhiya') ||
(person.gender == 'M' && address.state == 'bihar')
then
do something
How to accomplish this in drools rule file?
回答1:
Maybe this should be the solution:
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
来源:https://stackoverflow.com/questions/47430094/creating-rules-having-complex-conditions-using-multiple-data-objects