Jexl表达式语言引擎(4)-方法篇

import org.apache.commons.jexl3.*;
import org.junit.Test;

/**
 * Created by Main on 2019/3/28.
 */
public class MethodTest {

    private static final JexlEngine JEXL = new JexlBuilder().strict(true).silent(false).cache(32).create();

    public static class VarArgs {

        public String callInts() {
            int result = -5000;
            return "Varargs:" + result;
        }
    }

    @Test
    public void testCallVarArgMethod() throws Exception {
        VarArgs test = new VarArgs();
        JexlContext jexlContext = new MapContext();
        jexlContext.set("test", test);
        JexlExpression jexlExpression = JEXL.createExpression("test.callInts()");
        Object result = jexlExpression.evaluate(jexlContext);
        System.out.println(result);
    }
}

猜你喜欢

转载自www.cnblogs.com/Jmmm/p/10617298.html