Drools7规则引擎Map使用

service代码:

@Service
public class DroolsService {
    public String fireRule() {
        KieServices ks = KieServices.Factory.get();
        KieContainer kContainer = ks.getKieClasspathContainer();
        KieSession kSession = kContainer.newKieSession("ksession-rules");
        Map map=new HashMap<>();
        map.put("message","Hello World");
        map.put("status","0");
        kSession.insert(map);//插入
        kSession.fireAllRules();//执行规则
        kSession.dispose();
   	 }
}

规则文件:

1.用[]方式取值

	import java.util.Map;
	dialect  "java
	rule "Hello World"
    when
        $map:Map()
        $o : Object($map["status"]=="0");
    then
        System.out.println( $map.get("message"));
	end

2.用get()方式取值

	import java.util.Map;
	dialect  "java"

	rule "Hello World"
	    when
	        $map:Map()
	        $o : Object($map.get("status")=="0");
	    then
	        System.out.println( $map.get("message"));
	
	end

你可能感兴趣的:(Java)