Creating rules having complex conditions using multiple data objects

坚强是说给别人听的谎言 提交于 2019-12-25 02:22:59

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!