Drools版本:6.3.0.Final
POJO:
public class Person {
private Integer age;
private Integer childrens;
private String name;
private String address;
(...)
}
DSL文件:
[condition][]and=&&
[condition][]or=||
[condition][]is less than or equal to=<=
[condition][]is less than=<
[condition][]is greater than or equal to=>=
[condition][]is greater than=>
[condition][]is equal to===
[condition][]There is a [Pp]erson with=$person:Person()
[condition][].{field:\w*} {operator} {value:\d*}={field} {operator} {value}
(...)
DSRL文件:
package ;
import .*
global org.slf4j.Logger logger;
expander .dsl;
rule "R1"
when
There is a person with
.age is greater than 10 or .chidldrens is less than 2 and .name is equal to ""
then
(...)
end
rule "R2"
when
There is a person with
(.age is greater than 10 or .childrens is less than 2) and .name is equal to ""
then
(...)
end
DRL(来自R1):
(...)
rule "R1"
when
$person:Person(age > 10 || childrens < 2 && name = "")
then
(...)
end
(...)
DRL(来自R2):未生成规则.
如果我删除它的括号,但是使用括号,则无法正确生成DRL文件.所以只有R2规则正在运行,但我的目标是R1规则.
任何的想法?
解决方法:
我想我发现了一个可能的解决方案:
DSL文件(替换为这个新条件):
[condition][]There is a [Pp]erson that {constraints}=$person:Person({constraints})
[condition][]{field:\w*}\s+{operator}\s+{value:\s*}={field} {operator} {value}
DSRL(定义从第一行开始的约束):
(...)
There is a person that ((age is greater than 10 or chidldrens is less than 2) and name is equal to "")
(...)
DRL(生成):
(...)
$person:Person((age > 10 || childrens < 2) && name == "name")
(...)
使用这个新的DSL定义括号,它正在按预期工作.你怎么看@laune?
标签:java,jboss,dsl,drools,drools-flow
来源: https://codeday.me/bug/20190628/1313687.html