一个富有语言表现力的表达式引擎 Java 实现。
<dependency>
<groupId>io.github.slince</groupId>
<artifactId>expression</artifactId>
<version>0.0.2-RELEASE</version>
</dependency>
ObjectPath:
<dependency>
<groupId>io.github.slince</groupId>
<artifactId>expression-data-path</artifactId>
<version>0.0.2-RELEASE</version>
</dependency>
ObjectPath 使用文档见这里;
import io.github.slince.expression.Evaluator;
import io.github.slince.expression.MapContext;
import java.util.Arrays;
import java.util.List;
public class Book {
public static void main(String[] args) {
// 创建一本书实例
Book book = new Book("The Lady of the Camellias", 12.89f, Arrays.asList("Love Story", "France", null));
MapContext ctx = new MapContext();
ctx.setVar("book", book);
// 执行表达式
// "The Lady of the Camellias"
System.out.println(Evaluator.INSTANCE.evaluate("book.name", ctx));
// 3
System.out.println(Evaluator.INSTANCE.evaluate("book.tags|size", ctx));
// 22.89f
System.out.println(Evaluator.INSTANCE.evaluate("book.price + 10", ctx));
}
private final String name;
private final float price;
private final List<String> tags;
public Book(String name, float price, List<String> tags) {
this.name = name;
this.price = price;
this.tags = tags;
}
public String getName() {
return name;
}
public float getPrice() {
return price;
}
public List<String> getTags() {
return tags;
}
}
更多文档请查看详细文档
报告 Issue: github issues
The Apache 2.0 license. See Apache-2.0