diff --git a/src/main/java/com/ql/util/express/Operator.java b/src/main/java/com/ql/util/express/Operator.java index 5c3f52c82..5997fcc9e 100644 --- a/src/main/java/com/ql/util/express/Operator.java +++ b/src/main/java/com/ql/util/express/Operator.java @@ -45,6 +45,16 @@ public static int compareData(Object op1,Object op2) throws Exception{ compareResult = ((String)op1).compareTo(op2.toString()); }else if(op2 instanceof String){ compareResult = op1.toString().compareTo((String)op2); + }else if(op1 instanceof Character || op2 instanceof Character){ + if(op1 instanceof Character && op2 instanceof Character ){ + compareResult = ((Character) op1) .compareTo ((Character) op2); + }else if(op1 instanceof Number){ + compareResult = OperatorOfNumber.compareNumber((Number)op1, (int)((Character) op2).charValue()); + }else if(op2 instanceof Number){ + compareResult = OperatorOfNumber.compareNumber((int)((Character) op1).charValue(),(Number)op2); + }else { + throw new Exception(op1 + "和" + op2 + "不能执行compare 操作"); + } }else if(op1 instanceof Number && op2 instanceof Number){ //数字比较 compareResult = OperatorOfNumber.compareNumber((Number)op1, (Number)op2); diff --git a/src/test/java/com/ql/util/express/bugfix/CompareObjectTest.java b/src/test/java/com/ql/util/express/bugfix/CompareObjectTest.java new file mode 100644 index 000000000..cc5045b8d --- /dev/null +++ b/src/test/java/com/ql/util/express/bugfix/CompareObjectTest.java @@ -0,0 +1,31 @@ +package com.ql.util.express.bugfix; + +import com.ql.util.express.DefaultContext; +import com.ql.util.express.ExpressRunner; +import com.ql.util.express.IExpressContext; +import org.junit.Test; + +public class CompareObjectTest { + + @Test + public void test() throws Exception{ + + System.out.println('a'<98); + ExpressRunner runner = new ExpressRunner(); + String[] expList = new String[]{ + "'a'<'b'", + "'a'<='b'", + "'a'=='a'", + "test=='a'", + "test<='a'", + "'a'>=test", + }; + IExpressContext context = new DefaultContext(); + context.put("test",'a'+0); + for(String exp : expList) { + Object result = runner.execute(exp, context, null, true, false); + System.out.println(result); + assert (true == result); + } + } +}