zoukankan      html  css  js  c++  java
  • Spring表达式语言:SpEl

    概念:

      是一个支持运行时查询和操作的对象图的强大的表达式语言.

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

      SpEl为bean的属性进行动态赋值提供了便利

    通过SpEl可以实现:

      --通过bean的id对bean进行引用

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

      --计算表达式的值

      --正则表达式的匹配

    <bean id="address" class="com.tanlei.spring.SpEl.Address">
       <!-- 使用spel为属性赋值一个字面值 -->
         <property name="city" value="#{'BeiJing'}"></property>
         <property name="street" value="长沙"></property>
       </bean>
       
       <bean id="car" class="com.tanlei.spring.SpEl.Car">
       <!-- 使用spel为属性赋值一个字面值 -->
         <property name="brand" value="Aodi"></property>
         <property name="price" value="400000"></property>
         <!-- 使用spel 引用类的静态属性 -->
         <property name="tyrePerimeter" value="#{T(java.lang.Math).PI*80}"></property>
       </bean>
       
       <bean id="person" class="com.tanlei.spring.SpEl.Person">
      
         <property name="name" value="Tom"></property>
          <!-- 使用spel为引用其他的bean -->
         <property name="car" value="#{car}"></property>
         <!-- 使用SpEl来引用其他的bean的属性 -->
         <property name="city" value="#{address.city}"></property>
         
         <property name="info" value="#{car.price > 400000 ?'金额':'白领'}"></property>
       </bean>
  • 相关阅读:
    Centos 端口开放 Firewall
    windows 命令
    macOS 提示已损坏无法打开解决办法
    Linux screen
    pixhawk入门知识
    [转]错误记录
    华为上机试题:最高分是多少
    [转]opencv学习资料
    像素点的Hessian矩阵
    排序算法
  • 原文地址:https://www.cnblogs.com/tanlei-sxs/p/10129248.html
Copyright © 2011-2022 走看看