Java 在droolsdrl中使用POJO的hashmap
我对Drools非常陌生,并将其用于快速原型。 我有一个Pojo类,它有两个hashmapJava 在droolsdrl中使用POJO的hashmap,java,hashmap,drools,Java,Hashmap,Drools,我对Drools非常陌生,并将其用于快速原型。 我有一个Pojo类,它有两个hashmap public class MyTestClass { private Map<String, Integer> currMap= new HashMap<>(); private Map<String, Integer> historyMap = new HashMap<>(); } 然而,当我运行这个程序时,即使test1和test2规则
public class MyTestClass
{
private Map<String, Integer> currMap= new HashMap<>();
private Map<String, Integer> historyMap = new HashMap<>();
}
然而,当我运行这个程序时,即使test1和test2规则匹配,我也只从test3获得输出。我甚至修改了test3规则,以查找不存在的密钥(用一些垃圾字符替换了“Name 3”),但仍然只获取最后一个规则test3的输出。在使用HashMap时,我的drl文件在语法上似乎有问题
有人能帮我在drl文件写入规则中使用HashMap的值吗
谢谢,请添加创建和插入事实的代码。您的所有
System.out.println
中都缺少双引号。这是你帖子中的错误吗?或者你的DRL看起来像这样?双引号是个打字错误。更正了。谢谢
rule "test1"
when
$mc : MyTestClass(currMap["Name 1"] == 1, historyMap["Name 1"] == null)
then
System.out.println("Condition for Name 1 matched");
end
rule "test2"
when
$mc : MyTestClass(currMap["Name 2"] == 1, historyMap["Name 2"] == null)
then
System.out.println("Condition for Name 2 matched");
end
rule "test3"
when
$mc : MyTestClass(currMap["Name 3"] == 1, historyMap["Name 3"] == null)
then
System.out.println("Condition for Name 3 matched");
end