1、Spring 表达式语言(简称SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言
2、语法类似于 EL:SpEL 使用 #{…} 作为定界符,所有在大框号中的字符都将被认为是 SpEL
3、SpEL 为 bean 的属性进行动态赋值提供了便利
4、通过 SpEL 可以实现:
①通过 bean 的 id 对 bean 进行引用
②调用方法以及引用对象中的属性
③计算表达式的值
④正则表达式的匹配
5、注意事项:详细注释或者需要注意的都写到spelContext.xml的注释中
6、文件
①TestSpel.java:测试类
②SpelBean.java:数据模型
③SpelBean2.java:数据模型
④SpelBean3.java:数据模型
⑤spelContext.xml:配置文件
7、TestSpel.java
package com.demo.sshtest.spel;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
public class TestSpel {
public static void main(String[] args) {
scope();
}
public static void scope(){
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spelContext.xml");
SpelBean spelBean = (SpelBean)applicationContext.getBean("spelbean");
System.out.println(spelBean);
}
}
8、SpelBean.java
package com.demo.sshtest.spel;
public class SpelBean {
private Integer id;
private String name;
private double number;
private boolean judge;
private SpelBean2 spelBean2;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}