首页 > 代码库 > struts2的BaseAction<T>继承ActionSupport实现ModelDriven<T>
struts2的BaseAction<T>继承ActionSupport实现ModelDriven<T>
public class BaseAction<T> extends ActionSupport implements ModelDriven<T> { private static final long serialVersionUID = 1L; protected T model; //页面表单映射到model相当于struts1的formbean //将所有的service写入到BaseAction中 @Resource protected RoleService roleService; @Resource protected DepartmentService departmentService; @Resource protected UserService userService; @Resource protected PrivilegeService privilegeService; // 页码默认为第1页 protected int pageNum = 1; @SuppressWarnings({ "rawtypes", "unchecked" }) public BaseAction() { try { // 得到model的类型信息 ParameterizedType type = (ParameterizedType) this.getClass().getGenericSuperclass(); Class clazz = (Class) type.getActualTypeArguments()[0]; // 通过反射生成model的实例 model = (T) clazz.newInstance(); } catch (Exception e) { throw new RuntimeException(e); } } public T getModel() { return model; }}
struts2的BaseAction<T>继承ActionSupport实现ModelDriven<T>
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。