private static final long serialVersionUID = 4007195369050749902L;
public void init() throws ServletException {
super.init();
try {
**ServletContext context = this.getServletContext();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context); **
**Product_typeService product_typeService=wac.getBean("product_typeServiceImpl", Product_typeService.class);**
List<Product_type> product_type_list = product_typeService.getAllList();
** context.setAttribute("product_type_list",product_type_list);**
} catch (Exception e) {
System.out.println("===============数据字典缓存加载失败:"+ e.getMessage());
}
}
}
**ServletContext context = this.getServletContext();
WebApplicationContext wac = WebApplicationContextUtils.getRequiredWebApplicationContext(context); **
这两句的意思就是获取你的IOC容器的上下文环境,得到之后。
**Product_typeService product_typeService=wac.getBean("product_typeServiceImpl", Product_typeService.class);**
通过getBean 把这个bean对象获取到。 bean对象就是"product_typeServiceImpl", Product_typeService.class 这两个类的对象。
然后通过 List<Product_type> product_type_list = product_typeService.getAllList(); 获取一个list
在通过 context.setAttribute("product_type_list",product_type_list);** 将上句获得到的product_type_list 值 赋值给"product_type_list" 这个属性。
context.setAttribute("product_type_list",product_type_list)这一段代码是不是把一个list存储到上下文里面