简体   繁体   English

我如何从流口水的对象列表中获取变量列表

[英]How do I get a list of variables from the list of objects in drools

My rule is as follows: 我的规则如下:

when
  C : Company()
  $empname : List() collect from (Employee($empname : empname) from C.employees)
then
  System.out.println($empname);

The corresponding class: 对应的类:

public class Company {
  private List<Employee> employees;
  private Stringlocation;
}

public class Employee {
  private String empname;  
  private int empid;
}

With my code, I am only getting the Employee Objects but how do I get the empnames list? 通过我的代码,我仅获得Employee Objects,但是如何获得empnames列表?

It's preferable to implement simple data processing algorithms as methods in the class where they belong. 最好将简单的数据处理算法实现为它们所属类中的方法。 Writing rules for this is possible but it's the wrong tool. 为此可以编写规则,但这是错误的工具。

rule "employees"
when
   Company( $emps: employees )
   accumulate( Employee( $name: empname ) from $emps; 
               $name: collectList( $name ) )
then
   ... use List $name
end

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM