SpEL表达式简单使用
1.介绍
格式:
#{}
在Spring中有${}和SpEL表达式相似,
- ${}主要用来进行外部资源参数的获取,Spring框架中引入外部配置文件属性值
- SpEL:Spring Expression Language 目的是支持运算,在IOC容器进行对象属性的注入
参考文档:
官网地址:https://docs.spring.io/spring/docs/4.3.28.RELEASE/spring-framework-reference/htmlsingle/
pdf下载:
链接:https://pan.baidu.com/s/1C2c18oEiHpluYNrifdoHnQ
提取码:su1w
2.使用
2.1 简单参数传递
- 给一个类中的Double类型字段传递参数
#{5.0}
public class Bean1 {
private Double num;
public void setNum(Double num) {
this.num = num;
}
public Double getNum() {
return num;
}
}
demo1.xml配置
<?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 name="bean1" class="com.example.Bean1">
<property name="num" value="#{5.0}"></property>
</bean>
</beans>
测试类Demo1
public class Demo1 {
public static void main(String[] args) {
Cla