You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
import com.ql.util.express.DefaultContext;
import com.ql.util.express.ExpressRunner;
import com.ql.util.express.config.QLExpressRunStrategy;
import java.util.ArrayList;
import java.util.List;
public class Main {
public static void main(String[] args) throws Exception {
// testClassFunction();
testServiceFunction();
}
private static void testClassFunction() throws Exception {
QLExpressRunStrategy.setCompareNullLessMoreAsFalse(true);
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
context.put("a", null);
context.put("b", 2);
context.put("c", 3);
runner.addFunctionOfClassMethod("取绝对值", Math.class.getName(), "abs", new String[] {"double"}, null);
runner.addFunctionOfClassMethod("转换为大写", BeanExample.class.getName(), "upper", new String[] {"String"}, null);
runner.addFunctionOfClassMethod("转换为小写", BeanExample.class.getName(), "lower", new String[] {"String"}, null);
String express = "转换为小写(转换为大写(a)) == c;";
List<String> errorList = new ArrayList<>();
runner.getOperatorFactory().getOperator("==").setErrorInfo("$1等于$2");
Object r = runner.execute(express, context, errorList, true, false);
System.out.println(r);
}
private static void testServiceFunction() throws Exception {
QLExpressRunStrategy.setCompareNullLessMoreAsFalse(true);
ExpressRunner runner = new ExpressRunner();
DefaultContext<String, Object> context = new DefaultContext<String, Object>();
context.put("a", null);
context.put("b", 2);
context.put("c", 3);
BeanServiceExample beanServiceExample = new BeanServiceExample();
runner.addFunctionOfServiceMethod("upper", beanServiceExample, "upper", new String[] {"String"}, null);
runner.addFunctionOfServiceMethod("lower", beanServiceExample, "lower", new String[] {"String"}, null);
String express = "beanServiceExample = new org.example.BeanServiceExample(); return beanServiceExample.lower(beanServiceExample.upper(a)) == c;";
List<String> errorList = new ArrayList<>();
runner.getOperatorFactory().getOperator("==").setErrorInfo("$1等于$2");
Object r = runner.execute(express, context, errorList, true, false);
System.out.println(r);
}
}
testServiceFunction方法报错空指针异常:
Exception in thread "main" com.ql.util.express.exception.QLBizException: run QlExpress Exception at line 1 :
at com.ql.util.express.instruction.detail.InstructionOperator.execute(InstructionOperator.java:38)
at com.ql.util.express.InstructionSet.executeInnerOriginalInstruction(InstructionSet.java:200)
at com.ql.util.express.InstructionSet.execute(InstructionSet.java:164)
at com.ql.util.express.InstructionSetRunner.execute(InstructionSetRunner.java:64)
at com.ql.util.express.InstructionSetRunner.execute(InstructionSetRunner.java:55)
at com.ql.util.express.InstructionSetRunner.executeOuter(InstructionSetRunner.java:19)
at com.ql.util.express.ExpressRunner.executeReentrant(ExpressRunner.java:655)
at com.ql.util.express.ExpressRunner.executeInner(ExpressRunner.java:641)
at com.ql.util.express.ExpressRunner.execute(ExpressRunner.java:629)
at org.example.Main.testServiceFunction(Main.java:48)
at org.example.Main.main(Main.java:13)
Caused by: java.lang.NullPointerException: Cannot invoke "Object.toString()" because "parameters[index]" is null
at com.ql.util.express.ExpressUtil.replaceString(ExpressUtil.java:597)
at com.ql.util.express.instruction.op.OperatorBase.execute(OperatorBase.java:61)
at com.ql.util.express.instruction.detail.InstructionOperator.execute(InstructionOperator.java:32)
... 10 more
BeanServiceExample:
package org.example;
public class BeanServiceExample {
public String upper(String abc) {
if (null == abc) {
return null;
}
return abc.toUpperCase();
}
public String lower(String abc) {
if (null == abc) {
return null;
}
return abc.toLowerCase();
}
public boolean anyContains(String str, String searchStr) {
char[] s = str.toCharArray();
for (char c : s) {
if (searchStr.contains(c+"")) {
return true;
}
}
return false;
}
}
BeanExample:
public class BeanExample {
public static String upper(String abc) {
if (null == abc) {
return null;
}
return abc.toUpperCase();
}
public static String lower(String abc) {
if (null == abc) {
return null;
}
return abc.toLowerCase();
}
public boolean anyContains(String str, String searchStr) {
char[] s = str.toCharArray();
for (char c : s) {
if (searchStr.contains(c+"")) {
return true;
}
}
return false;
}
}
The text was updated successfully, but these errors were encountered:
现象描述:
结果说明:
pom依赖:
测试主类:
testServiceFunction方法报错空指针异常:
BeanServiceExample:
BeanExample:
The text was updated successfully, but these errors were encountered: