Drools7.4.1教程(5)-workbench规则开发与测试
drools,是由JBOSS公司开源的一套基于JAVA的规则引擎系统
规则进行时
假设我们现在要做一个考试评分的规则,60-70分以上为及格,70-90分以上良好,90-100分为优秀
新建数据对象
由于其实规则项目就是一个maven项目,所以我们先新建一个软件包,再建立一个数据对象package com.myteam.demo.entity; /** * This class was automatically generated by the data modeler tool. */ @javax.persistence.Entity public class ScoreRule implements java.io.Serializable { static final long serialVersionUID = 1L; @javax.persistence.GeneratedValue(generator = "SCORERULE_ID_GENERATOR", strategy = javax.persistence.GenerationType.AUTO) @javax.persistence.Id @javax.persistence.SequenceGenerator(name = "SCORERULE_ID_GENERATOR", sequenceName = "SCORERULE_ID_SEQ") private java.lang.Long id; //分数 private int score; //结果 private String result; public ScoreRule() { } public ScoreRule(java.lang.Long id) { this.id = id; } public java.lang.Long getId() { return this.id; } public void setId(java.lang.Long id) { this.id = id; } public int getScore() { return score; } public void setScore(int score) { this.score = score; } public String getResult() { return result; } public void setResult(String result) { this.result = result; } }
再建立一个规则,直接贴代码
package com.myteam.demo.rules; import com.myteam.demo.entity.ScoreRule; no-loop rule "excellent" when s:ScoreRule(score>=90&&score<=100) then System.out.println("excellent"); modify(s) { setResult("excellent") }; end rule "good" when s:ScoreRule(score>=70&&score<90) then System.out.println("good"); modify(s) { setResult("good") }; end rule "pass" when s:ScoreRule(score>=60&&score<70) then System.out.println("pass"); modify(s) { setResult("pass") }; end rule "nopass" when s:ScoreRule(score<60) then System.out.println("nopass"); modify(s) { setResult("nopass") }; end
新建一个测试场景
如果大家觉得好,哈哈,可以给我点鼓励,谢谢大家。