package com.zdc;
import org.springframework.expression.Expression;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class BiaoDaShi {
public static void main(String[] args) {
/**
* spring sp EL表达式
*/
String str1 = "3*5+2*4";//直接量表达式
String str2 = "new int[]{1,2,3,4}";//创建数组
String str3 = "{'java','phton'}";//转换集合
//创建解析器
ExpressionParser exp = new SpelExpressionParser();
//解析器解析字符串
Expression expression1 = exp.parseExpression(str1);
Expression expression2 = exp.parseExpression(str2);
Expression expression3 = exp.parseExpression(str3);
//调用Expression的getValue方法
System.out.println(expression1.getValue());
System.out.println(expression2.getValue());
System.out.println(expression3.getValue());
}
}