Spring教程

SPEL运算符

我们可以在SpEL中使用许多运算符,例如算术,关系,逻辑等。给出了很多在SpEL中使用不同运算符的示例。

在SPEL中使用运算符的示例

import org.springframework.expression.ExpressionParser;
import org.springframework.expression.spel.standard.SpelExpressionParser;
public class Test {
public static void main(String[] args) {
ExpressionParser parser = new SpelExpressionParser();
//arithmetic operator
System.out.println(parser.parseExpression("'Welcome SPEL'+'!'").getValue());
System.out.println(parser.parseExpression("10 * 10/2").getValue());
System.out.println(parser.parseExpression("'Today is: '+ new java.util.Date()").getValue());
//logical operator
System.out.println(parser.parseExpression("true and true").getValue());
//Relational operator
System.out.println(parser.parseExpression("'sonoo'.length()==5").getValue());
}
}
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4