Service

注解 @Service

交给 IOC 成为 Bean

使用接口形式进行多个 Bean 的管理:

注解在 Service 实例中

1
2
3
4

@Service
public class EmpServiceImpl implements EmpService {
}

注入对象 @Autowired

Controller 中

1
2
3
4

public class DeptController {
@Autowired
private DeptService deptService; // 这里类型是接口类型

必须保证有对应的 Bean 实例