Spring表达式语言:SqEL

Spring 表达式语言(简称SpEL):是一个支持运行时查询和操作对象图的强大的表达式语言。
语法类似于 EL:SpEL 使用 #{…} 作为定界符,所有在大框号中的字符都将被认为是 SpEL
SpEL 为 bean 的属性进行动态赋值提供了便利
   通过 SpEL 可以实现:
   》通过 bean 的 id 对 bean 进行引用
   》 调用方法以及引用对象中的属性
   》计算表达式的值
   》正则表达式的匹配


字面量的表示:
整数:
小数:
科学计数法:
String可以使用单引号或者双引号作为字符串的定界符号:
Boolean:


练习如下

三个pojo类

package cn.com.day04;

public class Cars {
	private String brand;
	private Integer price;
	// 轮胎的周长
	private double circle;

	public void setCircle(double circle) {
		this.circle = circle;
	}

	public void setBrand(String brand) {
		this.brand = brand;
	}

	public void setPrice(Integer price) {
		this.price = price;
	}

	public Integer getPrice() {
		return price;
	}

	public Cars() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public String toString() {
		return "Cars [brand=" + brand + ", price=" + price + ", circle="
				+ circle + "]";
	}

}
package cn.com.day04;

public class Address {
private String add;
private String id;
public void setAdd(String add) {
	this.add = add;
}
public void setId(String id) {
	this.id = id;
}
public String getAdd() {
	return add;
}
@Override
public String toString() {
	return "Address [add=" + add + ", id=" + id + "]";
}
public Address() {
	// TODO Auto-generated constructor stub
	System.out.println("address constructor....");
}
}
package cn.com.day04;

public class Person {
private String name;
private String as;
private Cars car;
private String info;
public void setName(String name) {
	this.name = name;
}
public void setAs(String add) {
	this.as = add;
}
public void setCar(Cars car) {
	this.car = car;
}
public void setInfo(String info) {
	this.info = info;
}
@Override
public String toString() {
	return "Person [name=" + name + ", as=" + as + ", car=" + car + ", info="
			+ info + "]";
}

public Person() {
	// TODO Auto-generated constructor stub
	System.out.println("deal......");
}
}

测试类

package cn.com.day04;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class TestMain {
public static void main(String[] args) {
	//1.创建ioc容器
	System.out.println("heheh");
	//1.创建ioc容器
	ApplicationContext cox=new ClassPathXmlApplicationContext("bean-spel.xml");
	//2.获取bean
//	Cars c1=(Cars) cox.getBean("car");	
//	System.out.println(c1);		
//	Address a1=(Address)cox.getBean("address");
//	System.out.println(a1);
	System.out.println("hahah");
	Person pp=(Person) cox.getBean("person1");
	System.out.println(pp);
}
}

bean配置文件如下



	
		
		
		
		
		
	
	
		
		
	
	
	
	
		
		
		
		
		
		
	

结果如下

Spring表达式语言:SqEL_第1张图片

你可能感兴趣的:(java之ssh框架专栏)