每个action都用到的存储代码,抽取出来
package org.com.cay.action;import java.util.Map;import org.apache.struts2.interceptor.ApplicationAware;import org.apache.struts2.interceptor.RequestAware;import org.apache.struts2.interceptor.SessionAware;import com.opensymphony.xwork2.ActionSupport;public class BaseActions extends ActionSupport implements RequestAware,SessionAware,ApplicationAware, ModelDriven{ private static final long serialVersionUID = 1L; protected HttpServletRequest req = ServletActionContext.getRequest(); protected HttpServletResponse response = ServletActionContext.getResponse(); protected Map request; protected Map session; protected Map application; protected T model; @Override public void setApplication(Map application) { this.application = application; } @Override public void setSession(Map session) { this.session = session; } @Override public void setRequest(Map request) { this.request = request; } @Override public T getModel() { ParameterizedType pt = (ParameterizedType)this.getClass().getGenericSuperclass(); // 获取泛型父类 Class clazz = (Class ) pt.getActualTypeArguments()[0]; // 获取第一个参数的真实类型 try { model = (T)clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } return model; }}