标签:集合 upper bbb 命名 调用 line www express 表达式
Spring支持前两种
构造函数注入
<bean id="user" class="com.demo.ioc.user">
<constructor-arg name="name" value="张三"/>
<constructor-arg name="age" value="23"/>
</bean>
属性setter方法注入
<bean id="person" class="com.Person">
<property name="name" value="里斯"/>
<property name="age" value="32">
<property name="cat" ref="cat">
</bean>
<bean id="cat" class="com.Cat">
<property name="name" value="ketty"/>
</bean>
p名称空间
在命名空间中添加
xmlns="http://www.springframework.org/schema/p"
<bean id="person" class="com.demo.Person" p:name="大黄"/>
<bean id="cat" class="com.demo.cat" p:name="小黄"/>
SpEL注入
SpEL表达式语言
语法:#{}
#{‘hello‘}:使用字符串
#{beanId}:使用另一个bean
#{beanId.content.toUpperCase()}:使用指定名属性,并调用它的方法
#{T(java.lang.Math).PI}:使用静态字段或方法
<bean>
<property name="name" value="#{服装}"/>
</bean>
<bean id="productInfo" class=""/>
<bean>
<property name="name"/>
<property name="price" value="#{productInfo.calculatePrice()}">
<property name="category" value="#{category}"/>
</bean>
1.数组类型的属性注入
2.List集合类型的属性注入
3.Set集合类型的属性注入
4.Map集合类型的属性注入
<!--集合类型的属性注入-->
<bean id="collectionBean" class="">
<!--数组类型-->
<property name="arrs">
<list>
<value>aaa</value>
<value>bbb</value>
<value>ccc</value>
</list>
</property>
<!--List集合的属性注入-->
<property name="list">
<list>
<value>111</value>
<value>222</value>
<value>333</value>
</list>
</property>
<!--Map集合的属性注入-->
<property name="map">
<map>
<entry key="aaa" value="111"/>
<entry key="bbb" value="222"/>
<entry key="ccc" value="333"/>
</map>
</property>
<!--Properties的属性注入-->
<property name="properties">
<props>
<prop key="username">root</prop>
<prop key="password">1234</prop>
</props>
</property>
</bean>
标签:集合 upper bbb 命名 调用 line www express 表达式
原文地址:https://www.cnblogs.com/yangHS/p/11384408.html