gpt4 book ai didi

java - 希望使用简单的规则 api 构建 java 动态规则引擎

转载 作者:行者123 更新时间:2023-11-30 11:01:35 27 4
gpt4 key购买 nike

我有许多规则要根据我们数据库中的数据进行评估,我计划使用 easyrules api。我不喜欢在我的代码中编程或硬编码规则。构建代码后,更改规则标准应该很容易。请帮助我如何使它动态和可读。Easyrules api 坚持为每个规则创建一个单独的类,如下所示:我希望根据易于修改的规则输入动态构建以下代码:我正在考虑以下但不确定哪个是最好的:1. DB 表——带有规则条件的规则表。 (我可以使用更新查询来更改规则)2. JSON 或 XML。

我对其他工具也很灵活,并不局限于 easyrules。 https://github.com/j-easy/easy-rules/wiki/hello-world

/**
* Hello World rule class.
*
* @author Mahmoud Ben Hassine (mahmoud@benhassine.fr)
*/
@Rule(name = "Hello World rule", description = "Say Hello to duke's friends only")
public class HelloWorldRule {

/**
* The user input which represents the data that the rule will operate on.
*/
private String input;

@Condition
public boolean checkInput() {
//The rule should be applied only if the user's response is yes (duke friend)
return input.equalsIgnoreCase("yes");
}

@Action
public void sayHelloToDukeFriend() throws Exception {
//When rule conditions are satisfied, prints 'Hello duke's friend!' to the console
System.out.println("Hello duke's friend!");
}

public void setInput(String input) {
this.input = input;
}

最佳答案

我可能会建议您使用 java + groovySrcipt 引擎。您可以在 GroovyScripts 中提供您的规则,并可以使用 GroovyEngine 动态地执行它们。这只是一个想法。

关于java - 希望使用简单的规则 api 构建 java 动态规则引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31107629/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com