IOC创建对象方式
public class User {
private String name;
public User(String name) {
this.name = name;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public void show() {
System.out.println("name =" + name )
}
}
-
使用无参构造创建对象(默认)
-
假设我们要使用有残构造创建对象
-
下标赋值
<bean id = "user" class "com.User">
<constructor-arg index = "0" value ="YanAemons"
</bean> -
类型(不推荐)
<bean id = "user" class "com.User">
<constructor-arg type="java.lang.String" value ="YanAemons"
</bean> -
参数名
<bean id = "user" class "com.User">
<constructor-arg name="name" value ="YanAemons"
</bean>
-
总结