# wft-spring
**Repository Path**: wft740/wft-spring
## Basic Information
- **Project Name**: wft-spring
- **Description**: No description available
- **Primary Language**: Java
- **License**: Not specified
- **Default Branch**: master
- **Homepage**: None
- **GVP Project**: No
## Statistics
- **Stars**: 0
- **Forks**: 0
- **Created**: 2022-04-17
- **Last Updated**: 2022-04-17
## Categories & Tags
**Categories**: Uncategorized
**Tags**: None
## README
# Spring
## Spring对象的创建
* Person对象
```java
package com.wft.bean;
public class Person {
private Integer id;
private String name;
private Integer age;
private String gender;
public Person() {
System.out.println("Person is created.");
}
public Person(Integer id) {
this.id = id;
}
public Person(Integer id, String name, Integer age) {
this.id = id;
this.name = name;
this.age = age;
}
public Person(Integer id, String name, String gender) {
this.id = id;
this.name = name;
this.gender = gender;
}
public Person(Integer id, String name, Integer age, String gender) {
this.id = id;
this.name = name;
this.age = age;
this.gender = gender;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public void setPk(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getAge() {
return age;
}
public void setAge(Integer age) {
this.age = age;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
@Override
public String toString() {
return "Person{" +
"id=" + id +
", name='" + name + '\'' +
", age=" + age +
", gender='" + gender + '\'' +
'}';
}
}
```
* 配置文件:spring.xml
```xml
```
* 获取对象
> 通过Bean的id获取IOC容器中的对象
```java
@Test
public void test02() {
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
Person person = applicationContext.getBean("person", Person.class);
System.out.println(person);
}
```
> 通过Bean的类型获取IOC容器中的对象
```java
@Test
public void test02() {
// 当有多个Person对象的时候:No qualifying bean of type 'com.wft.bean.Person' available: expected single matching bean but found 2: person,person2
ApplicationContext applicationContext = new ClassPathXmlApplicationContext("spring.xml");
Person person = applicationContext.getBean(Person.class);
System.out.println(person);
}
```
## Spring属性的复制
* 通过构造器给Bean对象赋值