Spring的EL表达式

需要依赖

<dependencies>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-coreartifactId>
            <version>3.2.4.RELEASEversion>
        dependency>
        <dependency>
            <groupId>org.springframeworkgroupId>
            <artifactId>spring-contextartifactId>
            <version>3.2.4.RELEASEversion>
        dependency>
    dependencies>

代码

public static void main(String[] args) {
        EvaluationContext context = new StandardEvaluationContext();

        User user = new User(99, "Dubby", "123456");
        context.setVariable("user", user);

        ExpressionParser parser = new SpelExpressionParser();


        String sourceStr = "'User:ID:'.concat(#user.id)";
        String destStr = parser.parseExpression(sourceStr).getValue(context, String.class);
        System.out.println(destStr);
    }

你可能感兴趣的:(spring)