有没有人有任何使用循环的简单 JEXL 示例。我希望围绕一个简单的对象数组列表进行迭代以输出各种字符串值?
输入 452' 的完整示例如下:
Run Code Online (Sandbox Code Playgroud)public static void testSimpleList() { List<String> list = new ArrayList<String>(); list.add("one"); list.add("two"); JexlContext jexlContext = new MapContext(); jexlContext.set("list", list);; Map<String, Object> functions1 = new HashMap<String, Object>(); functions1.put("system", System.out); JexlEngine jexl = new JexlEngine(); jexl.setFunctions(functions1); Expression expression = jexl.createExpression("for(item : list) { system:println(item) }"); expression.evaluate(jexlContext); }
输出 :
Run Code Online (Sandbox Code Playgroud)one two