SpEL

์ง€์› ๊ธฐ๋Šฅ

์ƒ˜ํ”Œ

@Value("#{1+1}")
int value;

@Value("#{'hello ' + 'world'}")
String greeting;

@Value("#{1 eq 5}")
boolean trueOrFalse;

@Value("Literal String")
String literalString;

@Override
public void run(ApplicationArguments args) throws Exception {
  System.out.println(value);
  System.out.println(greeting);
  System.out.println(trueOrFalse);
  System.out.println(literalString);
}

Properties

my.value=100
@Value("#{'${my.value}' eq '100'}")
boolean isEqual;

@Override
public void run(ApplicationArguments args) throws Exception {
  System.out.println(isEqual);
}

ExpressionParser

ExpressionParser parser = new SpelExpressionParser();
Expression expression = parser.parseExpression("1+1");
Object value = expression.getValue();
System.out.println(value);    // 2

Language Reference

์ƒ˜ํ”Œ

ExpressionParser parser = new SpelExpressionParser();

// evals to "Hello World"
String helloWorld = (String) parser.parseExpression("'Hello World'").getValue();

double avogadrosNumber = (Double) parser.parseExpression("6.0221415E+23").getValue();

// evals to 2147483647
int maxValue = (Integer) parser.parseExpression("0x7FFFFFFF").getValue();

boolean trueValue = (Boolean) parser.parseExpression("true").getValue();

Object nullValue = parser.parseExpression("null").getValue();

ref

What Else?
inflearn react api server -50% ํ• ์ธ์ฟ ํฐ: 15108-f2af1e086101 buy me a coffee