Spring Exoression Language
What is Spring Expression Language?
Spring Expression Language is just expression language in Spring. Supported since spring 3.0.
Several way to Expression Spel, first write in ‘#{}’ literal.
- Plus Integer.
- Plus String.
- Expression Boolean.
- Get property (using ‘${ }’ literal).
- Get Bean.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
public class SpelRunner implements ApplicationRunner {
"#{1 + 1}") //Plus Integer. (
int value;
"#{'hello ' + 'world'}") //Plus String. (
String greeting;
"#{1 eq 1}") //Expression Boolean. (
boolean trueOrFalse;
"${my.value}") //Get property. (
int myValue;
"#{${my.value} eq 100}") //Expression Boolean of get property. (
boolean isMyValue;
"#{'spring'}") //Expression just string (
String spring;
"#{sample.data}") //Get Bean. (
int sampleData;
public void run(ApplicationArguments args) throws Exception {
System.out.println("=============");
System.out.println(value);
System.out.println(greeting);
System.out.println(trueOrFalse);
System.out.println(myValue);
System.out.println(isMyValue);
System.out.println(spring);
System.out.println(sampleData);
}
}
Actually used
- Value annotation
- @ConditionalOnExpression annotation
- Spring Security
- Spring Data (@Query annotation)
- Thymeleaf