package com.yang.colademo.gatewayimpl;
import org.springframework.expression.EvaluationContext;
import org.springframework.expression.ExpressionParser;
import org.springframework.expression.common.TemplateParserContext;
import org.springframework.expression.spel.standard.SpelExpressionParser;
import org.springframework.expression.spel.support.StandardEvaluationContext;
/**
* @description:
* @author: Yang JianXiong
* @since: 2022/9/28
*/
public class Ui {
public static void main(String[] args) {
EvaluationContext context = new StandardEvaluationContext();
context.setVariable("name", "Yang JX");
context.setVariable("age", "29");
ExpressionParser parser = new SpelExpressionParser();
String value = parser
.parseExpression("====> 你好啊:#{#name}先生,祝贺你 #{#age} 岁生日快乐!", new TemplateParserContext())
.getValue(context, String.class);
System.err.println(value);
}
}
//输出:====> 你好啊:Yang JX先生,祝贺你 29 岁生日快乐!
标签:String,SpringEL,springframework,context,org,import,expression,表达式
From: https://www.cnblogs.com/JaxYoun/p/16739438.html