首页 > 代码库 > Spring初学之Spel初配
Spring初学之Spel初配
Spel又时候可以方便我们为bean的属性赋值,如下配置文件就是常用的一些使用:
<?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 id="address" class="spring.beans.spel.Address"> <!-- 使用SpEL设置字面值 --> <property name="city" value="#{‘重庆‘}"></property> <property name="more" value="梁平"></property> </bean> <bean id="car" class="spring.beans.spel.Car"> <property name="carName" value="#{‘奥迪‘}"></property> <property name="price" value="#{300000}"></property> <!-- 用SpEL引用类中的静态方法 --> <property name="tyrePermiter" value="#{T(java.lang.Math).PI*80}"></property> </bean> <bean id="person" class="spring.beans.spel.Person"> <!-- 使用SpEL设置字面值 --> <property name="name" value="#{‘Tom‘}"></property> <!-- 使用 SpEL引用其他bean--> <property name="car" value="#{car}"></property> <!-- 使用SpEL引用其它bean的属性 --> <property name="city" value="#{address.city}"></property> <!-- 在SpEl中使用运算符 --> <property name="info" value="#{car.price>300000?‘金领‘:‘白领‘}"></property> </bean> </beans>
Spring初学之Spel初配
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。