美文网首页
Spring学习笔记

Spring学习笔记

作者: mordor | 来源:发表于2017-12-11 17:45 被阅读0次
<bean id="kenny" class="com.spring.springidol.impl.Instrumentalist"
          p:song="Jingle Bells"
          p:instrument-ref="saxophone"
          p:age="37">
</bean>
<bean id="hank" class="com.spring.springidol.impl.OneManBand">
        <property name="song" value="#{kenny.song?.toUpperCase()}"/>
</bean>

?. 替代 . 当kenny.song返回null便不调用toUpperCase

SpEL中,使用T()运算符会调用类作用域的方法和常量
调用静态常量

①
<bean id="carl" class="com.spring.springidol.impl.Instrumentalist"
          p:song="#{T(java.lang.Math).PI}">
</bean>
②
System.out.println("Playing " + song + " : ");

输出结果:

Playing 3.141592653589793 : 

调用静态方法

①
<bean id="carl" class="com.spring.springidol.impl.Instrumentalist"
          p:song="#{T(java.lang.Math).random()}">
</bean>
②
System.out.println("Playing random " + song + " : ");

输出结果:

Playing random 0.729552083204084 : 

SpEL提供了几种运算符,这些运算符可以用在SpEL表达式中的值上。

运算符类型 运算符
算术运算 +、-、*、/、%、^
关系运算 <、>、==、<=、>=、lt、gt、eq、le、ge
逻辑运算 and、or、not、
条件运算 ?:(ternary)、?:(Elvis)
正则表达式 matches

相关文章

网友评论

      本文标题:Spring学习笔记

      本文链接:https://www.haomeiwen.com/subject/yzfwixtx.html