我有 drools 6.0.1 最终版本,我正在其中编写 DSL 文件。我的问题是我希望用户在运行时选择运算符。有没有办法可以在运行时更改运算符。例如,有两个具有不同值的变量,假设 A 和 B。我希望条件像这样 A {operator} B。我希望这个条件动态改变。
最佳答案
DSL Basics section of the Drools manual描述了如何执行此操作。但是,这里有一个摘要...
您还可以定义映射到运算符的多个 DSL 短语,例如:
[when][]is less than=<
[when][]is greater than=>
[when][]is equal to===
[when][]Given a person with=Person()
[when][]- {field:\w*} {operator} {value:\d*}={field} {operator} {value}
让你写:
Given a person with
- age is less than 18
为了让引导编辑器的工作更轻松,我还编写了枚举和 DSL,例如:
'InOrNotIn.options' : ['contains=in', 'not contains=not in']
[when][]Given a currency "{operator:ENUM:InOrNotIn.options}" the major currencies
= $ccy : Currency(isoCode {operator} $majorCurrencies)
关于java - 如何在 DSL 中动态更改运营商以应对流口水,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25389605/