Drl文件中的Drool全局变量初始化

时间:2019-03-12 14:13:13

标签: java drools kie

 package com.example.drools; 

 global Integer count; // I want to initialize this count variable with some 
                         default value. 

   rule "Initialize"
   when
   then
       count= 1; // Locally it's possible but want it to set globally which can 
                     be use in any other rules just simply by calling it.
       System.out.println("count="+count);
   end

  rule "Drools Introduction"
  when
  then
     System.out.println("count="+count); // Here output is coming null which in 
                                            want some default value set for 
                                            global value.
  end

所以只想在drl文件中初始化Count变量?

1 个答案:

答案 0 :(得分:1)

从规则内部更新全局变量的方法是使用自动变量const url = new URL("https://example.com/test") url.pathname = "/" console.log(url.toString())

kcontext

一些注意事项:

  • 您应该在规则中使用较高的显着性,以便在执行其他也使用全局规则的规则之前先执行它。
  • 如果您在规则的LHS中使用全局变量,则此方法将不起作用。如果是这种情况,我建议使用事实而非全局。

希望有帮助,