我是靠谱客的博主 耍酷画笔,最近开发中收集的这篇文章主要介绍Drools Using a Global variable to log information,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

Using a Global variable to log information

In the code we just did, we wrote the code System.out.println(“blabla”). This is fine but let us imagine you want to log somewhere else, it is not possible. One good practice is to use global variables for that purpose. We first define a java class called OutputDisplay that we shall create in the util package in src/main/java

在这里插入图片描述

Now we shall update the lesson1.drl file

在这里插入图片描述

The keyword global is used and then a normal java declaration. Here the global is of type OutputDisplay and the variable is called showResults. This variable can now be used in the “them” part of the rule as here.

To initialize the global variable, we shall use the method “setGlobal” on the session we create as shown here in our test :

在这里插入图片描述

When running the Junit test, the console should look like this :

在这里插入图片描述

最后

以上就是耍酷画笔为你收集整理的Drools Using a Global variable to log information的全部内容,希望文章能够帮你解决Drools Using a Global variable to log information所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(74)

评论列表共有 0 条评论

立即
投稿
返回
顶部