Visual Rules Solution Java Integration Interface <10>—List<E> class in Java classes and List<list> in VisualRules

The requirements of this case are:
rule package: create a new student entry rule package, this rule package accepts a series of parameters (number, name, gender, age, grade, remarks), inserts all data into the memory table, and defines a list <list> Query memory table data.
Java class call (different versions can be called): Create a Test10 class in Eclipse, receive the object in main, pass the object to the rule execution, query the execution result, execute the selected version, and execute the rule file under different versions. As can be seen from the above examples, the data in the student table called from the rule is of type list<list>, and here I hope it is data of type list<Student>.

Modify the rule package
Click the "Student Table Operation" tab of the memory table "Student Table", click the icon, as shown in the figure below:






Check the method getHeaderList(), as shown in the figure below:





Click OK, as shown in the figure below:




Modify the rule "Query Student Information", As shown in the figure below: The





modification operation is as shown in the figure below:
`



After replacement, the following figure is displayed:




Click the save icon to export the rule compilation file, as shown in the figure below:




Add a java class Add a java class
to the java project named StudentInfo.java, and its content is edited as follows:
package com.flagleader;
import java.util.ArrayList;
import java.util.List;
public class StudentInfo {
private Student student;
private List<Student> studentList = new ArrayList<Student>();
public StudentInfo() {
student = new Student(1, "Li Li", 12, 'male', "6th grade", "none");
}
public Student getStudent() {
return student;
}
public void setStudent(Student student) {
this.student = student;
}
public List<Student> getStudentList() {
return studentList;
}
public void setStudentList(List<Student> studentList) {
this. studentList = studentList;
}
}
Add a java class named Test10.java to the java project, and its content is edited as follows:
package com.flagleader;

import java.io.File;
import java.util.List;

import com.flagleader.engine.RuleEngine;
import com.flagleader.engine.RuleEngineException;
import com.flagleader.engine.RuleEngineFactory;
import com.flagleader.engine.RuleEngineManager;

/**
* Call the compiled file under the default file in the specified directory
* Using RuleEngine, this interface can only be used for local calls
* You can specify which version of the compiled file to execute in the directory.
* Such as RuleEngineFactory.getInstance("1.1").getRuleEngine();
* @author Administrator
*
*/
public class Test10 {
public static void main(String[] args) {
try {
// The specified directory for the compilation file, the default version directory is Default
RuleEngineManager.getInstance().init(new File("e:\\rscfile")) in the specified directory ;
// Factory mode, this interface can only be used for local calls, 1.1 in getInstance("1.1") is filename in the specified directory
RuleEngine engine = RuleEngineFactory.getInstance("1.3").getRuleEngine();
// Pass the parameter StudentInfo as the rule in the form of dto
studentInfo = new StudentInfo();
// Execute the rule, where "student.add" is the full name of the rule, student To pass in the parameter
engine.executeBeans("student.add", studentInfo.getStudent(),studentInfo);
// After executing the rule, get the data, "studentList" must be the same as the variable name of the memory table data in the rule
List< Student> list=studentInfo.getStudentList();
for (Student student : list) {
System.out.println(student.toString());
}
} catch (RuleEngineException e) {
// TODO Auto-generated catch block
e.printStackTrace ();
}
}
}
Execute the java test class After
clicking execute, you can see the following results:




It means that the student.add rule package has been called, and according to the parameters passed in, the returned processing results are displayed in the form of list<list>.
Similarly, any other java class can complete the work of calling the rule package by adding the above code.
Similarly, the above examples can be used in this way.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326743711&siteId=291194637