baseaction.java

来自「用STRUTS ,HIBERNATE, SPRING 三种框架整合做的实战项目」· Java 代码 · 共 52 行

JAVA
52
字号
package com.ghy.action;

import javax.servlet.ServletContext;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionServlet;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.ghy.service.book.BookServiceIfc;
import com.ghy.service.customer.CustomerServiceIfc;
import com.ghy.service.order.OrderServiceIfc;



public class BaseAction extends Action {
	private WebApplicationContext wac;
    private CustomerServiceIfc customerServiceIfc ;
    private BookServiceIfc bookServiceIfc ;
    private OrderServiceIfc orderServiceIfc;
		
		public void setServlet(ActionServlet actionServlet)
		{
			super.setServlet(actionServlet);
			if(actionServlet!=null)
			{
				ServletContext servletContext = actionServlet.getServletContext();
			 wac =	WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
			   customerServiceIfc=(CustomerServiceIfc)wac.getBean("customertransproxy");
			   bookServiceIfc=(BookServiceIfc)wac.getBean("booktransproxy");
			   orderServiceIfc = (OrderServiceIfc)wac.getBean("ordertransproxy");
			}
			
		}
		protected WebApplicationContext getWebApplicationContext() {
		    return wac;
		  }
        public CustomerServiceIfc getCustomerServiceIfc()
        {
        	return customerServiceIfc;
        }
        public BookServiceIfc getBookServiceIfc()
        {
        	return bookServiceIfc;
        }
        public OrderServiceIfc getOrderServiceIfc()
        {
        	return orderServiceIfc;
        }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?