七SpEl表达式

来源:互联网 发布:万方数据库中检索字段 编辑:程序博客网 时间:2024/06/08 01:27

语法类似于 EL:SpEL 使用 #{…} 作为定界符,所有在大框号中的字符都将被认为是 SpEL

通过 SpEL 可以实现:

通过 bean 的 id 对 bean 进行引用

调用方法以及引用对象中的属性

计算表达式的值

正则表达式的匹配

ex:

配置一个bean,并赋上字面值:

SpEl的基本操作:

<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans"       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">        <bean id="address" class="autowire.Address">            <property name="city" value="#{'wuxi'}"></property>            <property name="street" value="Binghujie"></property>                     <property name=“name” value="#{'Chuck'}"/>            <property name="enabled" value="#{false}"/>  </bean></beans>引用其他的对象: <property name="a" value="#{prefixGenerator}"></property>引用其他对象的属性:<property name="b" value="#{prefixGenerator.a}"></property>调用其他方法:<property name="c" value="#{prefixGenerator.toString()}"></property>链式调用:<property name="c" value="#{prefixGenerator.toString().toUpperCase()}"></property>if else运算符:<property name="info" value="#{car.price>300000?'金领':'白领'}"></property>正则:<property name='zz' value="#{admin.email matches '正则表达式'}"/>调用静态方法或者静态属性:<property name="pri" value="#{T(java.lang.Math).PI*80}"></property>


0 0
原创粉丝点击