-
Notifications
You must be signed in to change notification settings - Fork 206
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chapter7 add rule template array demo
- Loading branch information
Showing
3 changed files
with
67 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
drools-lesson2/src/main/java/com/secbro2/drools/demo/RuleTemplateArrayDemo.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package com.secbro2.drools.demo; | ||
|
||
import org.drools.template.DataProvider; | ||
import org.drools.template.DataProviderCompiler; | ||
import org.drools.template.objects.ArrayDataProvider; | ||
import org.kie.api.runtime.KieSession; | ||
|
||
import java.io.InputStream; | ||
|
||
/** | ||
* @author zzs | ||
*/ | ||
public class RuleTemplateArrayDemo extends BaseDemo { | ||
|
||
|
||
public static void main(String[] args) { | ||
|
||
InputStream template = RuleTemplateArrayDemo.class.getResourceAsStream("/com/template/template.drt"); | ||
|
||
DataProvider dataProvider = new ArrayDataProvider(new String[][]{ | ||
{"1", "Tom"}, {"2", "Lucy"} | ||
}); | ||
|
||
DataProviderCompiler compiler = new DataProviderCompiler(); | ||
|
||
String drl = compiler.compile(dataProvider, template); | ||
|
||
KieSession kieSession = getKieSessionByDrl(drl); | ||
|
||
Person person = new Person(1,""); | ||
|
||
kieSession.insert(person); | ||
|
||
kieSession.fireAllRules(); | ||
|
||
System.out.println("Person's username is " + person.getUsername()); | ||
|
||
|
||
} | ||
|
||
} |
Binary file modified
BIN
+0 Bytes
(100%)
drools-lesson2/src/main/resources/com/template/template.xls
Binary file not shown.