Spring小总结

静态注入

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
@Service
public class Teacher {

public static Student getStudent(Teacher teacher) {
return teacher.student;
}

@Autowired// 无论属性是否 public/private/省略 【属性不可加 static,@Autowired不可省略】
private Student student;

// private Student student;
// @Autowired// 无论setter public/private, 无论属性是否 static, 【setter方法不可加 static,@Autowired不可省略】
// public void setStudent(Student student) { this.student = student; }

// private static Student student;
// @Autowired// 无论构造 public/private, 无论构造上面是否要加@Autowired, 无论属性是否 static
// private Teacher(Student student) { this.student = student; }

// 总结于 2023-06-26 10:36:22
}