📄 baseaction.java
字号:
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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -