算术运算
@Test
public void test01() {
// 定义解析器
ExpressionParser parser = new SpelExpressionParser();
// 使用解析器解析表达式
Expression expression = parser.parseExpression("(1+2)*5 + 8-6/2");
// 获取解析结果
Assert.assertTrue(expression.getValue().equals(20));//加减乘除
Assert.assertTrue(parser.parseExpression("8%3").getValue().equals(2));//求余
Assert.assertTrue(parser.parseExpression("2.0e3").getValue().equals(2000.0));//指数
Assert.assertTrue(parser.parseExpression("2^3").getValue().equals(8));//指数
}
逻辑运算
@Test
public void test02() {
ExpressionParser parser = new SpelExpressionParser();
Assert.assertTrue(parser.parseExpression("true and true").getValue(Boolean.class));//与
Assert.assertTrue(parser.parseExpression("true or false").getValue(Boolean.class));//与
Assert.assertTrue(parser.parseExpression("!false").getValue(Boolean.class));//非
}
比较运算
@Test
public void test03() {
ExpressionParser parser = new SpelExpressionParser();
Assert.assertTrue(parser.parseExpression("5>3").getValue(Boolean.class));
Assert.assertTrue(parser.parseExpression("5<=8").getValue(Boolean.class));
Assert.assertTrue(parser.parseExpression("5==5").getValue(Boolean.class));
Assert.assertTrue(parser.parseExpression("5!=6").getValue(Boolean.class));
}
使用字符代替符号
@Test
public void test19() {