spring--(11)表達式語言(spel)

//Address類java

public class Address {
	private String city;
	private String street;
}

//Car類code

public class Car {
	private String brand;
	private double price;
	private double typeCircle;
}

//person類xml

public class Person {
	private String name;
	private Car car;
	private String city;
	private String info;
}

//xml配置文件ci

<bean id="address" class="com.test.autowired.Address">
		<!-- 使用spel爲屬性賦一個字面值 -->
		<property name="city" value="#{'BeiJing'}"></property>
		<property name="street" value="Wudaokou"></property>
	</bean>
	
	<bean id="car" class="com.test.autowired.Car">
		<property name="brand" value="Audi"></property>
		<property name="price" value="500000"></property>
		<property name="typeCircle" value="#{T(java.lang.Math).PI * 80}"></property>
	</bean>
	
	<bean id="person" class="com.test.autowired.Person">
		<property name="car" value="#{car}"></property>
		<property name="city" value="#{address.city}"></property>
		<property name="info" value="#{car.price > 300000 ? '金領':'白領'}"></property>
	</bean>
相關文章
相關標籤/搜索