@Controller
public class BookServlet {
@Autowired
private BookService bookservice;
public void doGet() {
bookservice.save();
}
}
@Service
public class BookService {
@Autowired
private BookDao bookDao;
public void save() {
System.out.println("正在调用BookDao进行保存图书..");
bookDao.saveBook();
}
}
@Repository
public class BookDao {
public void saveBook() {
System.out.println("图书保存成功...");
}
}
@ContextConfiguration(locations = "classpath:applicationContext.xml")
@RunWith(SpringJUnit4ClassRunner.class)
public class iocTest {
@Autowired
BookServlet bookServlet;
@Test
public void test01() {
bookServlet.doGet();
}
}
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |