标签:io 使用 java ar art cti 代码 on c
1.忘记了好像前几篇没写BaseAction,这个Action的改进是为了节省开发的代码,将Action中公共的代码提取出来,系统各自的Action只需要继承BaseAction即可代码如下:
package com.icss.oa.base; import java.lang.reflect.ParameterizedType; import javax.annotation.Resource; import com.icss.oa.domain.Department; import com.icss.oa.domain.User; import com.icss.oa.service.DepartmentService; import com.icss.oa.service.RoleService; import com.icss.oa.service.UserService; import com.opensymphony.xwork2.ActionSupport; import com.opensymphony.xwork2.ModelDriven; public class BaseAction<T> extends ActionSupport implements ModelDriven<T> { @Resource protected RoleService roleService; @Resource protected DepartmentService departmentService ; @Resource protected UserService userService ; protected T model ; public BaseAction() { ParameterizedType pt = (ParameterizedType) this.getClass().getGenericSuperclass(); Class clazz = (Class) pt.getActualTypeArguments()[0]; try { model = (T) clazz.newInstance(); } catch (InstantiationException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IllegalAccessException e) { // TODO Auto-generated catch block e.printStackTrace(); } } public T getModel() { // TODO Auto-generated method stub return model; } }
需要将各个持久层实体的servcie层注入进来
标签:io 使用 java ar art cti 代码 on c
原文地址:http://blog.csdn.net/dq3wrr/article/details/39235707