Wednesday, July 18, 2012

Spring Expression Language (SpEL)

SpEL

SpEL is an Expression Language that wire the values into beans properties using expression at runtime.

Features

  • Literal expressions :-
    Integer Number :-
    <property name="num" value="#{5}">  
    The #{} markers are a clue to Spring that the content that they contain is a SpEL expression.

    Floating-point numbers :-
    <property name="num" value="#{50.5}"/>

    Scientific notation :-
    <property name="num" value="#{2e5}"/>

    String :-
    <property name='str' value='#{"laptop"}'/>
  • Boolean :- 
    <property name="val" value="#{true}"/>
    <property name="val" value="#{false}"/>
  • Referencing Beans :-
    <property name="name" value="#{Employee}"/>
    This is same as :-
    <property name="name" ref="Employee"/>

    Referring another bean property :-
    <bean id="cars" class="com.proj.vehicleApp.Cars"> 
         <property name="speed" value="#{bike.speed}" />
    </bean>
    Call Method :-
    <bean id="cars" class="com.proj.vehicleApp.Cars">   
        <property name="speed" value="#{bike.getSpeed()}" />
    </bean>
  • Arithmetic   +, -, *, /, %, ^
  • Relational   <, >, ==, <=, >=, lt, gt, eq, le, ge
  • Logical and, or, not, |
  • Conditional ?: (ternary), ?: (Elvis)
  • Regular expression matches

2 comments:

ShareThis