日期:2014-05-17 浏览次数:20894 次
@Component
public class IndexController implements Controller {
private CategoryService categoryService;
public CategoryService getCategoryService() {
return categoryService;
}
@Resource
public void setCategoryService(CategoryService categoryService) {
this.categoryService = categoryService;
}
public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
System.out.println("categoryService:"+categoryService);
List<Category> list=categoryService.list();
request.setAttribute("list",list);
return new ModelAndView("common/index");
}
}
@Component("categoryService")
public class CategoryServiceImpl implements CategoryService {
private CategoryDAO categoryDAO;
public CategoryDAO getCategoryDAO() {
return categoryDAO;
}
@Resource
public void setCategoryDAO(CategoryDAO categoryDAO) {
this.categoryDAO = categoryDAO;
}
public List<Category> list() {
return categoryDAO.list();
}
}
@Component("categoryDAO")
public class CategoryDAOImpl implements CategoryDAO {
private HibernateTemplate hibernateTemplate;
public HibernateTemplate getHibernateTemplate() {
return hibernateTemplate;
}
@Resource
public void setHibernateTemplate(HibernateTemplate hibernateTemplate) {
this.hibernateTemplate = hibernateTemplate;
}
public List<Category> list() {
return hibernateTemplate.find(" from Category");
}
}