掌握Spring框架的依赖注入方式:构造注入和setter注入。
public class Student123 {
private int number;
private String name;
private String birthday;
public Student123() {
}
public Student123(int number, String name, String birthday) {
this.number = number;
this.name = name;
this.birthday = birthday;
}
public int getNumber() {
return number;
}
public void setNumber(int number) {
this.number = number;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getBirthday() {
return birthday;
}
public void setBirthday(String birthday) {
this.birthday = birthday;
}
@Override
public String toString() {
return "Student123{" +
"number=" + number +
", name='" + name + '\'' +
", birthday='" + birthday + '\'' +
'}';
}
}
`
我在实体类中创建了有参构造方法,也创建了get和set方法,在使用构造方法给属性赋值时没有出错,但是使用set方法给属性赋值时发生了错误,经老师提醒,原来是因为有参构造方法将原来的无参方法覆盖,而使用set方法时回调用无参方法。重新补上无参方法可行