美文网首页
SpringMVC 在jsp页面中如何取得service层的be

SpringMVC 在jsp页面中如何取得service层的be

作者: 我是陈君本 | 来源:发表于2016-12-13 10:03 被阅读186次

    在实际开发中 ,你可能会在jsp页面在写java代码,免不了要调用实现service层的接口

    由于Spring这个容器在Web程序运行起来后,其中的所有对象都已经被装入到了ApplicationContext对象(即Spring容器)中,所以可以

    直接从容器中将bean直接取出来

    /*从Spring容器中获取 service的bean对象*/

    ServletContext sc = this.getServletContext();

    ApplicationContext ac = WebApplicationContextUtils.getWebApplicationContext(sc);

    OrderService orderService = (OrderService)ac.getBean("OrderService");//这里就可以直接取出所需要的service层的Bean了

    相关文章

      网友评论

          本文标题:SpringMVC 在jsp页面中如何取得service层的be

          本文链接:https://www.haomeiwen.com/subject/tobvmttx.html