SpringEL表达式

本文详细解析了Spring框架中Bean的配置方式,包括使用XML进行Bean的定义,以及如何在Bean属性中利用SpEL表达式进行动态值注入,展示了Spring的强大灵活性和扩展性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:util="http://www.springframework.org/schema/util"
	xmlns:p="http://www.springframework.org/schema/p"
	xmlns:context="http://www.springframework.org/schema/context"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
		http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.0.xsd
		http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-4.0.xsd">
  
<bean id="car" class="com.Greatest.Spring2.dbutil.Car" >
<property name="brand" value="#{'路虎揽胜'}" ></property>
<property name="price" value="#{car.brand ne '路虎揽胜'? 100000:200000}" ></property>
<!-- <property name="price" value="#{456*2.0}" ></property>
LE小于等于     lt小于  gt大于  eq等于 ne不等于  -->
<!-- 调用静态方法或静态属性:通过 T() 调用一个类的静态方法,它将返回一个 Class Object,然后再调用相应的方法或属性: 
 -->
<property name="maxSpeed" value="#{T(java.lang.Math).PI^5}" ></property>
 <!-- <property name="fat" value="#{true}"></property> -->
<!--返回值是布尔类型的    <property name="fat" value="#{car.price eq 10000}"></property> -->
 <property name="fat" value="#{car.price==100000 or car.maxSpeed>10}"></property>
 </bean>
 <bean id="person" class="com.Greatest.Spring2.dbutil.Person">
		 <property name="name" value='#{car.toString()+" "+car.price+""}'></property>
		 <property name="car" value="#{car}"></property>
 </bean>
</beans>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值