我有一个用例,其中一个对象带有一个字符串,该字符串具有针对另一个对象的属性进行评估的条件。
例如。
StudentEvaluator
有条件
student.pastScore>70 && student.currentScore>90 && student.sportsParticipation=true
和Student
对象有各自的属性。
E.g. pastScore, currentScore and sportsParticipation
现在 StudentEvaluator
条件字符串是在运行时创建的,必须评估是真还是假。
有许多 StudentEvaluator 在不同条件下并行运行。
现在 StudentEvaluator 在其评估函数中接受学生参数并评估条件。
即
public Class StudentEvaluator{
String condition;
public StudentEvaluator(String condition){
this.condition = condition;
}
evaluate(Student student){
<<Code>>
}
}
什么是最有效的评估方法? 欢迎任何开箱即用的想法! :)
最佳答案
过去做过。您有多种选择
- OGNL
- MVEL - 比 OGNL 更高效。支持 logical and conditional operators.
- SpEL - Spring Expression Language - 我的偏好。
关于JAVA动态属性条件求值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13311277/