baseaction.java

来自「订货系统:这是在Eclipse环境下开发的」· Java 代码 · 共 48 行

JAVA
48
字号
package cn.hxex.order.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 cn.hxex.order.service.IOrderService;

/**
 * Action基类
 * 
 * @author galaxy
 */
public abstract class BaseAction extends Action {

	private IOrderService orderService;

	public void setServlet(ActionServlet actionServlet) {
		super.setServlet(actionServlet);
		ServletContext servletContext = actionServlet.getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletContext);
		this.orderService = (IOrderService) wac.getBean("orderService");
	}

	protected IOrderService getOrderService() {
		return orderService;
	}

	/**
	 * 公共的getBean方法
	 * 用于得到Spring中定义的Bean的实例
	 * 
	 * @param beanId Bean的id
	 * @return
	 */
	protected Object getBean(String beanId) {
		ServletContext servletContext = getServlet().getServletContext();
		WebApplicationContext wac = WebApplicationContextUtils
				.getRequiredWebApplicationContext(servletContext);
		return wac.getBean(beanId);
	}

}

⌨️ 快捷键说明

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