parent
50c429cde1
commit
62b6823392
@ -0,0 +1,21 @@
|
||||
package com.ssm.ioc;
|
||||
|
||||
public class Material {
|
||||
private Integer mid;
|
||||
private String name;
|
||||
|
||||
public Material() {
|
||||
System.out.println("Material 对象被 Spring 创建了");
|
||||
}
|
||||
|
||||
public void setMid(Integer mid) { this.mid = mid; }
|
||||
public void setname(String name) { this.name = name; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Material{mid=" + mid + ", mname='" + name + "'}";
|
||||
}
|
||||
|
||||
public void setMname(String mname) {
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,18 @@
|
||||
package com.ssm.ioc;
|
||||
|
||||
public class User {
|
||||
private Integer id;
|
||||
private String username;
|
||||
|
||||
public User() {
|
||||
System.out.println("User 对象被 Spring 创建了");
|
||||
}
|
||||
|
||||
public void setId(Integer id) { this.id = id; }
|
||||
public void setUsername(String username) { this.username = username; }
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "User{id=" + id + ", username='" + username + "'}";
|
||||
}
|
||||
}
|
||||
@ -1,19 +0,0 @@
|
||||
package src.com.ssm.ioc;
|
||||
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
public class TestIoc {
|
||||
public static void main(String[] args) {
|
||||
// 读取spring配置文件
|
||||
ApplicationContext ac = new ClassPathXmlApplicationContext("bean-ioc.xml");
|
||||
|
||||
// 获取实验室对象,打印信息
|
||||
Lab lab = (Lab) ac.getBean("labBean");
|
||||
System.out.println(lab);
|
||||
|
||||
// 获取材料对象,打印信息
|
||||
Material material = (Material) ac.getBean("materialBean");
|
||||
System.out.println(material);
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue