我需要使用MVEL评估标准字符串。我能够比较所有原始值。我在比较日期时遇到了问题。 MVEL支持默认日期格式' dd-MMM-yyyy'但是我需要使用MVEL将工具日期与字符串Date进行比较。以下代码通过异常
Shared files
例外
public class Person {
private int age;
private String name;
private Date joiningDate;
public Date getJoiningDate() {
return joiningDate;
}
public void setJoiningDate(Date joiningDate) {
this.joiningDate = joiningDate;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
public class App {
public static void main(String[] args) {
Person person = new Person();
person.setName("Raja");
person.setAge(30);
Calendar calendar=Calendar.getInstance();
//24-August -2016
calendar.set(2016, 7, 24);
Date joiningDate = calendar.getTime();
person.setJoiningDate(joiningDate);
// all the constant fetched from DB
String criteria = "name == 'Raja' && age == 30 && joiningDate <=\"24-Aug-2016\"";
System.out.println("Is Criteria match : "+isCriteriaMatch(criteria, person));
}
private static boolean isCriteriaMatch(String criteria, Object object) {
boolean istrue = false;
if (criteria != null && !criteria.isEmpty()) {
istrue = MVEL.evalToBoolean(criteria, object);
}
return istrue;
}
private static String formatDate(Date date){
System.out.println("Date : "+date);
SimpleDateFormat sdf = new SimpleDateFormat("dd-MMM-yyyy");
return "\"".concat(sdf.format(date)).concat("\"");
//return sdf.format(date);
}
}