开始重新捡起spring了
需要赶紧加快进度才能跟上团队,但是还是要慢慢来,寒假学的拉跨就是因为走马观花
spring是解耦的一种方式
下面是例子
public class UserServiceImpl implements UserService {
private UserDao userDao;
// 利用set实现
public void setUserDao(UserDao userDao) { this.userDao = userDao;
}
@Override
public void getUser() {
userDao.getUser();
}
}
@Testpublic void test(){
UserServiceImpl service = new UserServiceImpl();
service.setUserDao( new UserDaoMySqlImpl() );
service.getUser();
//那我们现在又想用Oracle去实现呢
service.setUserDao( new UserDaoOracleImpl() );
service.getUser();
}