`

Drools6.4简单应用之决策表

阅读更多

1.rule.xls

2.DecisionTableTest.java

 

/**
 * caicongyang.com Inc.
 * Copyright (c) 2004-2016 All Rights Reserved.
 */
package com.caicongyang.drools.drools;

import java.io.File;

import org.drools.decisiontable.SpreadsheetCompiler;
import org.kie.api.KieServices;
import org.kie.api.runtime.KieContainer;
import org.kie.api.runtime.KieSession;
import org.kie.internal.io.ResourceFactory;

import u51.test.person.Person;

/**
 * @author caicongyang1
 * @version id: tableTest, v 0.1 16/11/28 下午8:16 caicongyang1 Exp $$
 */
public class DecisionTableTest {

    /**
     * 默认规则文件所在路径
     */
    private static final String RULES_PATH = "tables";

    public static void main(String[] args) {
        //把excel翻译成drl文件
        SpreadsheetCompiler compiler = new SpreadsheetCompiler();
        String drl = compiler.compile(ResourceFactory.newClassPathResource(RULES_PATH + File.separator + "rule.xls", "UTF-8"), "rule-table");
        System.out.println(drl);
        Long start = System.currentTimeMillis();
        //执行决策表
        try {
            // load up the knowledge base
            KieServices ks = KieServices.Factory.get();
            KieContainer kContainer = ks.getKieClasspathContainer();
            KieSession kSession = kContainer.newKieSession("tablesKiession");
            Person person = new Person();
            person.setName("Tony");
            kSession.insert(person);
            kSession.fireAllRules();
            kSession.dispose();
        } catch (Throwable t) {
            t.printStackTrace();
        }
        System.out.println("COST:"+String.valueOf(System.currentTimeMillis()-start));

    }


}


结果:

 

 

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics