All Downloads are FREE. Search and download functionalities are using the official Maven repository.

in.hocg.boot.cache.autoconfiguration.utils.ElUtils Maven / Gradle / Ivy

There is a newer version: 1.0.63
Show newest version
package in.hocg.boot.cache.autoconfiguration.utils;

import lombok.experimental.UtilityClass;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;

@UtilityClass
public class ElUtils {

    public static  T parseSpEl(String text, String[] parameterNames, Object[] args) {
        // 创建解析器
        ExpressionParser parser = new SpelExpressionParser();

        // 构造上下文
        EvaluationContext context = new StandardEvaluationContext();
        for (int i = 0, len = parameterNames.length; i < len; i++) {
            context.setVariable(parameterNames[i], args[i]);
        }
        return (T) parser.parseExpression(text).getValue(context);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy