个人主页:个人主页
系列专栏:SSM框架
public class UserController {
private UserService userService;
public void setUserService(UserService userService) {
this.userService = userService;
}
public void saveUser(){
userService.saveUser();
}
}
public interface UserService {
void saveUser();
}
public class UserServiceImpl implements UserService {
private UserDao userDao;
public void setUserDao(UserDao userDao) {
this.userDao = userDao;
}
@Override
public void saveUser(){
userDao.saveUser();
}
}
public interface UserDao {
void saveUser();
}
public class UserDaoImpl implements UserDao {
@Override
public void saveUser() {
System.out.println("保存成功");
}
}
@Test
public void test2(){
ConfigurableApplicationContext ioc = new ClassPathXmlApplicationContext("spring-autowire-xml.xml");
UserController userController = ioc.getBean("userController", UserController.class);
userController.saveUser();
}