如何将drools的输出发送到java
下面是我根据情况使用的口水如何将drools的输出发送到java,java,drools,Java,Drools,下面是我根据情况使用的口水 import com.sample.TestExample; import com.sample.TestExample.Message; rule "Hello World" when m : Message( product == Message.tv, myMessage : message ) then System.out.println(Message.tv); System.out.println("Product Spec i
import com.sample.TestExample;
import com.sample.TestExample.Message;
rule "Hello World"
when
m : Message( product == Message.tv, myMessage : message )
then
System.out.println(Message.tv);
System.out.println("Product Spec is:: Service.TV_SAT"); // This output i want send back to java
end
rule "GoodBye"
when
n : Message( product == Message.smart, myMessage : message )
then
System.out.println(Message.smart);
System.out.println("Product Spec is:: Service.SMARTOFFICE"); // This output i want send back to java
end
rule "Else condition"
when
e : Message(product != TestExample.productClass)
then
System.out.println(TestExample.productClass);
System.out.println("in drools else condition"); // This output i want send back to java
end
我试着使用set和get方法,但不起作用
任何帮助都将不胜感激:-)不确定“发送回Java”是什么意思
您需要做什么取决于您希望将此“输出”存储在何处。如果在Message
中有字段messageText
,则可以
m.setMessageText( "your message" );
如果这不起作用,您可能没有声明此setter,或者您可能犯了其他错误。(我们需要看到setter的声明才能告诉您更多。)
您可以使用全局
列表并将消息文本添加到此集合对象。请参阅如何使用globals的文档。您好,我的代码在java代码中做了以下更改后正常工作
公共静态类消息{
private String message;
public static String product;
public static String tv="TV_SAT";
public static String smart="SMART_OFFICE";
public static String productSpec;
public static int status;
public String getProduct(){
return Message.product;
}
public String getMessage() {
return this.message;
}
public void setMessage(String message) {
this.message = message;
}
public void setProduct(String product){
Message.product=product;
}
public void setProductSpec(String product){
Message.productSpec=product;
}
public String getProductSpec(){
return
Message.productSpec;
}
}
最终drl文件如下所示:
package com.sample
import com.sample.TestExample;
import com.sample.TestExample.Message;
global java.util.List statuses;
rule "Hello World"
when
m : Message( product == Message.tv, myMessage : message )
then
System.out.println("Product Class::"+Message.tv);
m.setProductSpec("Service.TV_SAT");
end
rule "GoodBye"
when
n : Message( product == Message.smart, myMessage : message )
then
System.out.println("Product Class::"+Message.smart);
n.setProductSpec("Service.SmartOffice");
end
rule "Else condition"
when
e : Message(product != TestExample.productClass)
then
System.out.println(TestExample.productClass);
System.out.println("in drools else condition");
end
我尝试使用set函数-->>m.setProductSpec(“Service.TV_SAT”);感谢您的回复:-)“发送回Java”意味着由println()方法编写的输出应该发送回保存当前输出的Java变量。借助set()的帮助方法,它正在显示输出,但我需要存储该值。请共享“变量[…]保存当前输出”的文档链接?setter通常存储该变量,因此调用行为类似setter的文档链接。--“doc”是发行版附带的drools_文档。您的系统上有它。我正在使用java中的当前代码,请检查并验证public void setProductSpec(String product){system.out.println(“内部设置产品规范”);Message.product=product;}public String getProductSpec(){System.out.println(“内部获取产品规范”);返回消息.productSpec;