框架学习 Spring之依赖注入DI
2020-12-13 05:26
标签:list() class view 文件 util java lis setter 属性注入 依赖注入的方式有四种: 1、Setter注入(属性注入) 2、构造器注入 3、P命名空间注入 4、集合类型值注入 1、Setter注入(属性注入) Employee 员工实体类 Department 部门实体类 主配置文件里面 2、构造器注入
3、P命名空间注入 添加命名空间 xmlns:p="http://www.springframework.org/schema/p" 使用P标签 4、集合类型注入 创建collection集合实体类 主配置文件中,依赖注入 框架学习 Spring之依赖注入DI 标签:list() class view 文件 util java lis setter 属性注入 原文地址:https://www.cnblogs.com/luojack/p/11141004.htmlpackage com.spring.pojo;
public class Employee {
private Integer id;
private String name;
private Department department;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Department getDepartment() {
return department;
}
public void setDepartment(Department department) {
this.department = department;
}
@Override
public String toString() {
return "Employee [id=" + id + ", name=" + name + ", department=" + department + "]";
}
public Employee(Integer id, String name, Department department) {
super();
this.id = id;
this.name = name;
this.department = department;
}
public Employee() {
super();
// TODO Auto-generated constructor stub
}
}
package com.spring.pojo;
public class Department {
private Integer id;
private String name;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Department() {
super();
// TODO Auto-generated constructor stub
}
public Department(Integer id, String name) {
super();
this.id = id;
this.name = name;
}
@Override
public String toString() {
return "Department [id=" + id + ", name=" + name + "]";
}
}
package com.spring.pojo;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
public class CollectionBean {
private List