码迷,mamicode.com
首页 > 编程语言 > 详细

Spring初学之Spel初配

时间:2017-04-12 23:10:36      阅读:222      评论:0      收藏:0      [点我收藏+]

标签:cat   xsd   xmlns   ddr   logs   code   val   city   location   

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初配

标签:cat   xsd   xmlns   ddr   logs   code   val   city   location   

原文地址:http://www.cnblogs.com/hyyq/p/6701721.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!