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

    1、Spring表达式语言(简称:SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言

    2、语法类似于EL:SpEL使用#{...}作为定界符,所有在大括号内的字符都被认为是SpEL。

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

    4、通过SpEL可以实现:

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

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

    --计算表达式的值

    --正则表达式

    【SpEL:字面量】

    字面量的表示:

    --整数:<property name=“count” value=“#{5}”/>

    --小数:<property name=“frequency” value=“#{89.7}”/>

    --科学计数法:<property name=“capacity” value=“#{1e4}”/>

    --String可以使用单引号或者双引号作为字符串的定界符号:

      <property name="name" value="#{'Tom'}"/>或

      <property name="name" value='#{"Tom"}'/>

    --Boolean:<property name=“enabled” value=“#{false}”/>

    【SpEL:引用Bean、属性和方法(1)】

    (1)引用其他对象

    1 <!--通过value属性和SpEL配置Bean之间的应用关系-->
    2 <property name="prefix" value="#{prefixGenerator}"></property>

    (2)引用其他对象的属性

    1 <!--通过value属性和SpEL配置suffix属性值为另一个Bean的suffix属性值-->
    2 <property name="suffix" value="#{sequenceGenerator2.suffix}"/>

    (3)调用其他方法,还可以链式操作

    1 <!--通过value属性和SpEL配置suffix属性值为另一个Bean方法的返回值-->
    2 <property name="suffix" value="#{sequenceGenerator2.toString()}"/>
    1 <!--方法的连缀-->
    2 <property name="suffix" value="#{sequenceGenerator2.toString()。toUpperCase()}"/>

    (4)调用静态方法或者静态属性:通过T()调用一个类的静态方法,它将返回一个Class Object,然后再调用相应的方法或属性

    1 <property name="initValue" value="#{T(java.lang.Math).PI}"></property>

    【SpELl支持的运算符号】

    1、算数运算符:+,-,*,/,%,^。

    2、加号还可以用作字符串连接。

    3、比较运算符:<,>,==,<=,>=,It,gt,eg,le,ge

    4、逻辑运算度:and,or,not

    5、if-else运算符

    6、正则表达式:matches

    每接触一个新领域,我就像一块掉进水里的海绵,四面八方的养分都让我不断充实。O(∩_∩)O~
  • 相关阅读:
    lintcode:Find the Connected Component in the Undirected Graph 找出无向图汇总的相连要素
    lintcode:Recover Rotated Sorted Array恢复旋转排序数组
    lintcode:Number of Islands 岛屿的个数
    lintcode :Trailing Zeros 尾部的零
    lintcode:Flip Bits 将整数A转换为B
    lintcode:strStr 字符串查找
    lintcode:Subtree 子树
    lintcode 容易题:Partition Array by Odd and Even 奇偶分割数组
    lintcode:在二叉查找树中插入节点
    lintcode:在O(1)时间复杂度删除链表节点
  • 原文地址:https://www.cnblogs.com/zhzcode/p/9622835.html
Copyright © 2011-2022 走看看