第一个bean的方法
package com.lengxin1;
import lombok.Data;
import java.util.*;
@Data
public class lianxi1 {
private int age;
private Lianxi2 lianxi2;
private String[] books;
private List<String> pet;
private Map<String, String> games;
private Set<String> card;
private Properties info;
}
第二个bean的方法:
package com.lengxin1;
import lombok.Data;
@Data
public class Lianxi2 {
private String lianxi2;
}
基本注入:
<property name="age" value="18"></property>
多个bean注入:
<bean id="username" class="com.lengxin1.lianxi1"
<property name="lianxi2" ref="lianxi2"></property>
>
<bean id="lianxi2" class="com.lengxin1.Lianxi2">
<property name="lianxi2" value="8998"></property>
</bean>
List注入:
<property name="pet">
<list>
<value>789</value>
</list>
</property>
Map注入:
<property name="games">
<map>
<entry key="123" value="456"></entry>
<entry key="789" value="110"></entry>
</map>
</property>
Set注入:
<property name="card">
<set>
<value>123</value>
<value>456</value>
</set>
</property>
数组注入:
<property name="books">
<array>
<value>爱情爱</value>
<value>三月里</value>
</array>
</property>
配置文件注入:
<property name="info">
<props>
<prop key="Driver">com.mysql.jdbc.Driver</prop>
</props>
</property>
C命名和P命名空间注入(需要带入导入XML约束):
C命名:约束:xmlns:c=“http://www.springframework.org/schema/c”(有参构造)
<bean id="username" class="com.lengxin.lianxi1" c:pppp="888"><bean/>
P命名:约束:xmlns:p=“http://www.springframework.org/schema/p”(无参构造)
<bean id="username" class="com.lengxin1.lianxi1" p:age="18"><bean/>